Commits

Ben Woskow committed 52b0a17

bumping to 2.1-m8, adding marketplace buttons

Comments (0)

Files changed (3)

                             com.google.common*;version="1.0",
                             javax.servlet*;version="0.0",
                             org.apache.commons*;version="0.0",
+                            org.joda.time*;version="0.0",
                             org.osgi.framework*;version="0.0",
                             org.osgi.util*;version="0.0",
                             org.slf4j*;version="1.5",
     <properties>
         <amps.version>3.7.2</amps.version>
         <jira.version>5.0</jira.version>
-        <upm.license.compatibility.version>2.1-m7</upm.license.compatibility.version>
+        <upm.license.compatibility.version>2.1-m8</upm.license.compatibility.version>
     </properties>
 </project>
 

src/main/java/com/example/plugins/tutorial/servlet/LicenseServlet.java

 package com.example.plugins.tutorial.servlet;
 
 import java.io.IOException;
+import java.net.URI;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import com.atlassian.sal.api.ApplicationProperties;
 import com.atlassian.upm.api.license.entity.PluginLicense;
 import com.atlassian.upm.api.util.Option;
+import com.atlassian.upm.license.storage.lib.AtlassianMarketplaceUriFactory;
 import com.atlassian.upm.license.storage.lib.PluginLicenseStoragePluginUnresolvedException;
 import com.atlassian.upm.license.storage.lib.ThirdPartyPluginLicenseStorageManager;
 
  *  - get the current plugin license,
  *  - update the plugin license,
  *  - remove the plugin license,
+ *  - buy, try, upgrade, and renew your license directly from My Atlassian,
  *  - check for a licensing-aware UPM,
  *  - and properly handle if a licensing-aware UPM is detected.
  *
  * This servlet can be reached at http://localhost:2990/jira/plugins/servlet/licenseservlet
+ *
+ * Note that Atlassian does not recommend writing servlets in this manner. You should really look
+ * into using a templating library such as Velocity. This servlet is written this way solely for simplicity purposes.
  */
 public class LicenseServlet extends HttpServlet
 {
     private final ThirdPartyPluginLicenseStorageManager licenseManager;
+    private final AtlassianMarketplaceUriFactory uriFactory;
     private final ApplicationProperties applicationProperties;
 
-    public LicenseServlet(ThirdPartyPluginLicenseStorageManager licenseManager, ApplicationProperties applicationProperties)
+    public LicenseServlet(ThirdPartyPluginLicenseStorageManager licenseManager,
+                              AtlassianMarketplaceUriFactory uriFactory,
+                              ApplicationProperties applicationProperties)
     {
         this.licenseManager = licenseManager;
+        this.uriFactory = uriFactory;
         this.applicationProperties = applicationProperties;
     }
 
 
     private void outputBody(HttpServletResponse resp) throws ServletException, IOException
     {
+        URI servletUri = URI.create(applicationProperties.getBaseUrl() + "/plugins/servlet/licenseservlet");
         try
         {
             resp.getWriter().write("<br><br>UPM is licensing-aware: " + licenseManager.isUpmLicensingAware());
             if (!licenseManager.isUpmLicensingAware())
             {
                 resp.getWriter().write("<br><br>Update your license");
-                resp.getWriter().write("<br><form action=\"" + applicationProperties.getBaseUrl() + "/plugins/servlet/licenseservlet\" method=\"POST\">");
+                resp.getWriter().write("<br><form action=\"" + servletUri.toASCIIString() + "\" method=\"POST\">");
                 resp.getWriter().write("<textarea name=\"license\" cols=\"80\" rows=\"10\">");
                 for (String storedRawLicense : licenseManager.getRawLicense())
                 {
                 resp.getWriter().write("</textarea>");
                 resp.getWriter().write("<br><input type=\"submit\" value=\"Save\" />");
                 resp.getWriter().write("</form>");
+
+                //Display appropriate marketplace buttons
+                resp.getWriter().write("<br>");
+                if (uriFactory.isPluginBuyable())
+                {
+                    outputMarketplaceButton(uriFactory.getBuyPluginUri(servletUri), "Buy", resp);
+                }
+                if (uriFactory.isPluginTryable())
+                {
+                    outputMarketplaceButton(uriFactory.getTryPluginUri(servletUri), "Try", resp);
+                }
+                if (uriFactory.isPluginRenewable())
+                {
+                    outputMarketplaceButton(uriFactory.getRenewPluginUri(servletUri), "Renew", resp);
+                }
+                if (uriFactory.isPluginUpgradable())
+                {
+                    outputMarketplaceButton(uriFactory.getUpgradePluginUri(servletUri), "Upgrade", resp);
+                }
             }
             else
             {
                             "should resolve the problem.");
         }
     }
+
+    private void outputMarketplaceButton(URI buttonUri, String buttonText, HttpServletResponse resp) throws IOException
+    {
+        resp.getWriter().write("<form action=\"" + buttonUri + "\" method=\"POST\">");
+        resp.getWriter().write("<input type=\"submit\" value=\"" + buttonText + "\" />");
+        resp.getWriter().write("</form>");
+    }
 }

src/main/resources/atlassian-plugin.xml

   <component-import key="pluginController" interface="com.atlassian.plugin.PluginController"/>
   <component-import key="txTemplate" interface="com.atlassian.sal.api.transaction.TransactionTemplate"/>
   <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties"/>
+  <component-import key="pluginSettingsFactory" interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory"/>
 
   <component key="pluginLicenseStoragePluginInstaller" class="com.atlassian.upm.license.storage.lib.PluginLicenseStoragePluginInstaller"/>
   <component key="thirdPartyPluginLicenseStorageManager" class="com.atlassian.upm.license.storage.lib.ThirdPartyPluginLicenseStorageManagerImpl"/>
+  <component key="atlassianMarketplaceUriFactory" class="com.atlassian.upm.license.storage.lib.AtlassianMarketplaceUriFactoryImpl"/>
 
   <servlet name="License Servlet" i18n-name-key="license-servlet.name" key="license-servlet" class="com.example.plugins.tutorial.servlet.LicenseServlet">
     <description key="license-servlet.description">The License Servlet Plugin</description>