/**
  * Get a tenant by unique id.
  *
  * @param tenantId
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{tenantId}", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "Get tenant by unique id")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Response,
           json = Tenants.CreateTenantResponse.class,
           description = "getTenantByIdResponse.md")
     })
 public ITenant getTenantById(
     @ApiParam(value = "Tenant id", required = true) @PathVariable String tenantId,
     @ApiParam(value = "Include runtime info", required = false)
         @RequestParam(required = false, defaultValue = "false")
         boolean includeRuntimeInfo)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "getTenantById", LOGGER);
   try {
     ITenant tenant = SiteWhere.getServer().getUserManagement().getTenantById(tenantId);
     if (includeRuntimeInfo) {
       ISiteWhereTenantEngine engine = SiteWhere.getServer().getTenantEngine(tenantId);
       if (engine != null) {
         ((Tenant) tenant).setEngineState(engine.getEngineState());
       }
     }
     return tenant;
   } finally {
     Tracer.stop(LOGGER);
   }
 }
 /**
  * Get tenants associated with a user.
  *
  * @param username
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{username}/tenants", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "Find tenants associated with a given user")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public List<ITenant> getTenantsForUsername(
     @ApiParam(value = "Unique username", required = true) @PathVariable String username,
     @ApiParam(value = "Include runtime info", required = false)
         @RequestParam(required = false, defaultValue = "false")
         boolean includeRuntimeInfo)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "getAuthoritiesForUsername", LOGGER);
   try {
     List<ITenant> results = SiteWhere.getServer().getAuthorizedTenants(username);
     if (includeRuntimeInfo) {
       for (ITenant tenant : results) {
         ISiteWhereTenantEngine engine = SiteWhere.getServer().getTenantEngine(tenant.getId());
         if (engine != null) {
           ((Tenant) tenant).setEngineState(engine.getEngineState());
         }
       }
     }
     return results;
   } finally {
     Tracer.stop(LOGGER);
   }
 }