Commits

Ben Woskow  committed d49480d

updating tutorial code to confirm to sdk 3.10.1 code generator

  • Participants
  • Parent commits 5e553c4

Comments (0)

Files changed (6)

             <plugin>
                 <groupId>com.atlassian.maven.plugins</groupId>
                 <artifactId>maven-jira-plugin</artifactId>
-                <version>3.7.2</version>
+                <version>${amps.version}</version>
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
                             com.atlassian.upm.api.license;version="2.0.1",
                             com.atlassian.upm.api.license.entity;version="2.0.1",
                             com.atlassian.upm.api.util;version="2.0.1",
-                            com.atlassian.upm.license.storage.plugin;version="2.0.1"
+                            com.atlassian.upm.license.storage.plugin;version="${upm.license.compatibility.version}"
                         </DynamicImport-Package>
                     </instructions>
                     <productVersion>${jira.version}</productVersion>
         </dependency>
     </dependencies>
     <properties>
-        <amps.version>3.9.2</amps.version>
+        <amps.version>3.10.1</amps.version>
         <jira.version>5.0</jira.version>
-        <upm.license.compatibility.version>2.1</upm.license.compatibility.version>
+        <upm.license.compatibility.version>2.2.1</upm.license.compatibility.version>
     </properties>
 </project>
 

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

  *  - 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
+ * This servlet can be reached at http://localhost:2990/jira/plugins/servlet/com.example.plugins.tutorial.plugin-license-compatibility-tutorial/license
  */
 public class LicenseServlet extends HttpServlet
 {
     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
     {
-        if (!hasAdminPermission())
-        {
+        if (userManager.getRemoteUsername() == null)
+ 		{
             redirectToLogin(req, resp);
             return;
         }
+        else if (!hasAdminPermission())
+        {
+            handleUnpermittedUser(req, resp);
+            return;
+        }
 
         final Map<String, Object> context = initVelocityContext(resp);
         addEligibleMarketplaceButtons(context);
     @Override
     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
     {
-        if (!hasAdminPermission())
-        {
+        if (userManager.getRemoteUsername() == null)
+ 		{
             redirectToLogin(req, resp);
             return;
         }
+        else if (!hasAdminPermission())
+        {
+            handleUnpermittedUser(req, resp);
+            return;
+        }
 
         final Map<String, Object> context = initVelocityContext(resp);
 
             catch (PluginLicenseStoragePluginUnresolvedException e)
             {
                 context.put("errorMessage", i18nResolver.getText("plugin.license.storage.admin.plugin.unavailable"));
-                context.put("storagePluginIsAvailable", false);
+                context.put("displayLicenseAdminUi", false);
             }
         }
 
     private Map<String, Object> initVelocityContext(HttpServletResponse resp)
     {
         resp.setContentType("text/html;charset=utf-8");
-        URI servletUri = URI.create(applicationProperties.getBaseUrl() + "/plugins/servlet/licenseservlet");
+        URI servletUri = URI.create(applicationProperties.getBaseUrl() +
+                                    "/plugins/servlet/com.example.plugins.tutorial.plugin-license-compatibility-tutorial/license");
 
         final Map<String, Object> context = new HashMap<String, Object>();
-
-        resp.setContentType("text/html;charset=utf-8");
         context.put("servletUri", servletUri);
-        context.put("storagePluginIsAvailable", true);
+        context.put("displayLicenseAdminUi", true);
 
         try
         {
         catch (PluginLicenseStoragePluginUnresolvedException e)
         {
             context.put("errorMessage", i18nResolver.getText("plugin.license.storage.admin.plugin.unavailable"));
-            context.put("storagePluginIsAvailable", false);
+            context.put("displayLicenseAdminUi", false);
         }
 
         return context;
 
     private void addEligibleMarketplaceButtons(Map<String, Object> context)
     {
-        URI servletUri = URI.create(applicationProperties.getBaseUrl() + "/plugins/servlet/licenseservlet");
+        URI servletUri = URI.create(applicationProperties.getBaseUrl() +
+                                    "/plugins/servlet/com.example.plugins.tutorial.plugin-license-compatibility-tutorial/license");
 
         try
         {
         catch (PluginLicenseStoragePluginUnresolvedException e)
         {
             context.put("errorMessage", i18nResolver.getText("plugin.license.storage.admin.plugin.unavailable"));
-            context.put("storagePluginIsAvailable", false);
+            context.put("displayLicenseAdminUi", false);
         }
     }
 
         }
     }
 
-    private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException
+    private void redirectToLogin(HttpServletRequest req, HttpServletResponse resp) throws IOException
+    {
+        resp.sendRedirect(loginUriProvider.getLoginUri(URI.create(req.getRequestURL().toString())).toASCIIString());
+    }
+
+    private void handleUnpermittedUser(HttpServletRequest req, HttpServletResponse resp) throws IOException
     {
-        response.sendRedirect(loginUriProvider.getLoginUri(URI.create(request.getRequestURL().toString())).toASCIIString());
+        resp.setContentType("text/html;charset=utf-8");
+
+        final Map<String, Object> context = new HashMap<String, Object>();
+        context.put("errorMessage", i18nResolver.getText("plugin.license.storage.admin.unpermitted"));
+        context.put("displayLicenseAdminUi", false);
+        renderer.render(TEMPLATE, context, resp.getWriter());
     }
 }

File src/main/resources/atlassian-plugin.xml

 
   <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>
-    <url-pattern>/licenseservlet</url-pattern>
+    <url-pattern>/com.example.plugins.tutorial.plugin-license-compatibility-tutorial/license</url-pattern>
   </servlet>
   
   <servlet name="License Hello World Servlet" i18n-name-key="license-hello-world-servlet.name" key="license-hello-world-servlet" class="com.example.plugins.tutorial.servlet.LicenseHelloWorldServlet">
     <description key="license-hello-world-servlet.description">The License Hello World Servlet Plugin</description>
-    <url-pattern>/licensehelloworld</url-pattern>
+    <url-pattern>/com.example.plugins.tutorial.plugin-license-compatibility-tutorial/licensehelloworld</url-pattern>
   </servlet>
 
   <resource type="i18n" name="i18n" location="atlassian-plugin"/>

File src/main/resources/license-admin.properties

 
 plugin.license.storage.admin.plugin.unavailable=Sorry, but we cannot find the required licensing support to execute the requested operation. Please ensure that the Plugin License Storage plugin is installed and enabled. Restarting this plugin should resolve the problem.
 plugin.license.storage.admin.upm.licensing.aware=Sorry, you cannot update your plugin license on this screen. Please use the <a href=''{0}''>Plugin Manager</a> instead.
+plugin.license.storage.admin.unpermitted=Sorry, you are not permitted to manage this plugin''s license. Please log in as an administrator.
 plugin.license.storage.admin.license.update=The license you submitted is valid. Your license has been successfully updated.
 plugin.license.storage.admin.license.update.invalid=The license you submitted has an error. Your license has been updated. See below for more information.
 plugin.license.storage.admin.license.remove=Your license has successfully been removed.

File src/main/resources/license-admin.vm

             <div class="aui-message warning"><span class="aui-icon icon-warning"></span>$warningMessageWithHtml</div>
             #end
 
-            #if (!$upmLicensingAware && $storagePluginIsAvailable)
+            #if (!$upmLicensingAware && $displayLicenseAdminUi)
             <h4>$i18n.getText("plugin.license.storage.admin.license.details")</h4>
             <table class="aui">
                 <tbody>
                             <td>$i18n.getText("plugin.license.storage.admin.license.attribute.organization.title")</td>
                             <td>$license.get().organization.name</td>
                         </tr>
+                        #if ($license.get().serverId)
                         <tr>
                             <td>$i18n.getText("plugin.license.storage.admin.license.attribute.serverid.title")</td>
                             <td>$license.get().serverId</td>
                         </tr>
+                        #end
                         <tr>
                             <td>$i18n.getText("plugin.license.storage.admin.license.attribute.sen.title")</td>
                             <td>

File src/test/java/it/com/example/plugins/tutorial/servlet/LicenseServletFuncTest.java

     public void setup() {
         httpClient = new DefaultHttpClient();
         baseUrl = System.getProperty("baseurl");
-        servletUrl = baseUrl + "/plugins/servlet/licenseservlet";
+        servletUrl = baseUrl + "/plugins/servlet/com.example.plugins.tutorial.plugin-license-compatibility-tutorial/license";
     }
 
     @After