예제 #1
0
 /**
  * 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);
   }
 }
예제 #2
0
 @RequestMapping(value = "/{tenantId}/engine/{command}", method = RequestMethod.POST)
 @ResponseBody
 @ApiOperation(value = "Send command to tenant engine")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Response,
           json = Tenants.IssueTenantEngineCommandResponse.class,
           description = "issueTenantEngineCommandResponse.md")
     })
 public ICommandResponse issueTenantEngineCommand(
     @ApiParam(value = "Tenant id", required = true) @PathVariable String tenantId,
     @ApiParam(value = "Command", required = true) @PathVariable String command)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "issueTenantEngineCommand", LOGGER);
   try {
     ISiteWhereTenantEngine engine = SiteWhere.getServer().getTenantEngine(tenantId);
     if (engine == null) {
       throw new SiteWhereSystemException(ErrorCode.InvalidTenantEngineId, ErrorLevel.ERROR);
     }
     return engine.issueCommand(command, 10);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
예제 #3
0
 /**
  * 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);
   }
 }
예제 #4
0
 /**
  * Get the current configuration for a tenant engine.
  *
  * @param tenantId
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{tenantId}/engine/configuration", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "Get tenant engine configuration")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented
 public String getTenantEngineConfiguration(
     @ApiParam(value = "Tenant id", required = true) @PathVariable String tenantId)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "getTenantEngineConfiguration", LOGGER);
   try {
     ISiteWhereTenantEngine engine = SiteWhere.getServer().getTenantEngine(tenantId);
     if (engine == null) {
       throw new SiteWhereSystemException(ErrorCode.InvalidTenantEngineId, ErrorLevel.ERROR);
     }
     IVersion version = SiteWhere.getServer().getVersion();
     return engine.getConfigurationResolver().getTenantConfiguration(engine.getTenant(), version);
   } finally {
     Tracer.stop(LOGGER);
   }
 }