View Javadoc
1   package com.atlassian.plugin.refimpl.tenant;
2   
3   import com.atlassian.plugins.landlord.spi.LandlordRequestException;
4   import com.atlassian.plugins.landlord.spi.LandlordRequests;
5   import com.google.common.util.concurrent.SettableFuture;
6   
7   import java.util.ArrayList;
8   import java.util.Collections;
9   import java.util.List;
10  import java.util.Map;
11  
12  /**
13   * This class provides RefApp specific methods for handling new tenant requests from the Landlord plugin ( which
14   * currently arrive via REST calls )
15   */
16  public class RefappLandlordRequests implements LandlordRequests {
17  
18      private SettableFuture<Void> tenantTrigger;
19      private RefappTenantRegistry tenantRegistry;
20  
21      public RefappLandlordRequests(final SettableFuture<Void> tenantTrigger, final RefappTenantRegistry tenantRegistry) {
22          this.tenantTrigger = tenantTrigger;
23          this.tenantRegistry = tenantRegistry;
24      }
25  
26      @Override
27      public void acceptTenant(final String tenantId) throws LandlordRequestException {
28          acceptTenant(tenantId, Collections.<String, String>emptyMap());
29      }
30  
31      @Override
32      public void acceptTenant(final String tenantId, final Map<String, String> tenantProperties) throws LandlordRequestException {
33          tenantTrigger.set(null);
34          tenantRegistry.setTenant(new RefappTenant(tenantId));
35      }
36  
37      @Override
38      public void removeTenant(final String tenantId) throws LandlordRequestException {
39          throw new UnsupportedOperationException("Not implemented");
40      }
41  
42      @Override
43      public List<String> getTenants() {
44          final List<String> tenantIDs = new ArrayList<String>();
45          for (final RefappTenant tenant : tenantRegistry.getRefappTenants()) {
46              tenantIDs.add(tenant.getTenantID());
47          }
48          return tenantIDs;
49      }
50  }