コード例 #1
0
 /**
  * Lists all tenants that contain a device with the given hardware id.
  *
  * @param hardwareId
  * @param servletRequest
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/device/{hardwareId}", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "List tenants that contain a device")
 @Secured({SiteWhereRoles.REST})
 public List<ITenant> listTenantsForDevice(
     @ApiParam(value = "Hardware id", required = true) @PathVariable String hardwareId,
     HttpServletRequest servletRequest)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "listTenantsForDevice", LOGGER);
   try {
     List<ITenant> tenants =
         SiteWhere.getServer()
             .getAuthorizedTenants(LoginManager.getCurrentlyLoggedInUser().getUsername());
     List<ITenant> matches = new ArrayList<ITenant>();
     for (ITenant tenant : tenants) {
       if (SiteWhere.getServer().getDeviceManagement(tenant).getDeviceByHardwareId(hardwareId)
           != null) {
         matches.add(tenant);
       }
     }
     return matches;
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #2
0
 /**
  * Display the "assignment detail" page.
  *
  * @param token
  * @param request
  * @return
  */
 @RequestMapping("/assignments/{token}")
 public ModelAndView assignmentDetail(
     @PathVariable("token") String token, HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "assignmentDetail", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     ITenant tenant = (ITenant) data.get(DATA_TENANT);
     IDeviceManagement management = SiteWhere.getServer().getDeviceManagement(tenant);
     IDeviceAssignment assignment = management.getDeviceAssignmentByToken(token);
     if (assignment != null) {
       DeviceAssignmentMarshalHelper helper = new DeviceAssignmentMarshalHelper(tenant);
       helper.setIncludeDevice(true);
       assignment =
           helper.convert(assignment, SiteWhere.getServer().getAssetModuleManager(tenant));
       data.put("assignment", assignment);
       return new ModelAndView("assignments/detail", data);
     }
     return showError("Assignment for token '" + token + "' not found.");
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #3
0
  /**
   * View tenant details.
   *
   * @param tenantId
   * @param request
   * @return
   */
  @RequestMapping("/tenants/{tenantId}")
  public ModelAndView viewTenant(
      @PathVariable("tenantId") String tenantId, HttpServletRequest request) {
    Tracer.start(TracerCategory.AdminUserInterface, "viewTenant", LOGGER);
    try {
      Map<String, Object> data = createBaseData(request);

      // Pass JSON representation of tenant configuration model.
      TenantConfigurationModel configModel = new TenantConfigurationModel();
      String strConfigModel = MarshalUtils.marshalJsonAsString(configModel);
      data.put("configModel", strConfigModel);

      ITenant tenant = SiteWhere.getServer().getUserManagement().getTenantById(tenantId);
      if (tenant == null) {
        showError("Invalid tenant id.");
      }
      data.put("selected", tenant);

      // Pass JSON representation of configuration content.
      String strConfig = TenantUtils.getTenantConfiguration(tenantId);
      ElementContent elmConfig = ConfigurationContentParser.parse(strConfig);
      String config = MarshalUtils.marshalJsonAsString(elmConfig);
      data.put("config", config);

      return new ModelAndView("tenants/detail", data);
    } catch (NoTenantException e) {
      return showTenantChoices(getUrl(request), request);
    } catch (SiteWhereException e) {
      return showError(e);
    } finally {
      Tracer.stop(LOGGER);
    }
  }
コード例 #4
0
 /**
  * Update an existing tenant.
  *
  * @param tenantId
  * @param request
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{tenantId}", method = RequestMethod.PUT)
 @ResponseBody
 @ApiOperation(value = "Update an existing tenant.")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Request,
           json = Tenants.UpdateTenantRequest.class,
           description = "updateTenantRequest.md"),
       @Example(
           stage = Stage.Response,
           json = Tenants.UpdateTenantResponse.class,
           description = "updateTenantResponse.md")
     })
 public ITenant updateTenant(
     @ApiParam(value = "Tenant id", required = true) @PathVariable String tenantId,
     @RequestBody TenantCreateRequest request)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "updateTenant", LOGGER);
   try {
     return SiteWhere.getServer().getUserManagement().updateTenant(tenantId, request);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #5
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);
   }
 }
コード例 #6
0
 /**
  * View details about a batch command invocation.
  *
  * @param batchToken
  * @param request
  * @return
  */
 @RequestMapping("/batch/command/{token}")
 public ModelAndView batchCommandInvocationDetail(
     @PathVariable("token") String batchToken, HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "batchCommandInvocationDetail", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     ITenant tenant = (ITenant) data.get(DATA_TENANT);
     IDeviceManagement management = SiteWhere.getServer().getDeviceManagement(tenant);
     IBatchOperation operation = management.getBatchOperation(batchToken);
     if (operation != null) {
       data.put("operation", operation);
       String commandToken =
           operation.getParameters().get(IBatchCommandInvocationRequest.PARAM_COMMAND_TOKEN);
       if (commandToken == null) {
         return showError("No command token set for batch operation.");
       }
       IDeviceCommand command = management.getDeviceCommandByToken(commandToken);
       data.put("command", new String(MarshalUtils.marshalJsonAsString(command)));
       return new ModelAndView("batch/command", data);
     }
     return showError("Batch operation for token '" + batchToken + "' not found.");
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #7
0
 /**
  * Display the "device detail" page.
  *
  * @param hardwareId
  * @param request
  * @return
  */
 @RequestMapping("/devices/{hardwareId}")
 public ModelAndView deviceDetail(
     @PathVariable("hardwareId") String hardwareId, HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "deviceDetail", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     ITenant tenant = (ITenant) data.get(DATA_TENANT);
     IDeviceManagement management = SiteWhere.getServer().getDeviceManagement(tenant);
     IDevice device = management.getDeviceByHardwareId(hardwareId);
     if (device != null) {
       IDeviceSpecification specification =
           management.getDeviceSpecificationByToken(device.getSpecificationToken());
       data.put("device", device);
       data.put("specification", specification);
       return new ModelAndView("devices/detail", data);
     }
     return showError("Device for hardware id '" + hardwareId + "' not found.");
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #8
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);
   }
 }
コード例 #9
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);
   }
 }
コード例 #10
0
 /**
  * List devices that match given criteria.
  *
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "List users that match certain criteria")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public SearchResults<User> listUsers(
     @ApiParam(value = "Include deleted", required = false) @RequestParam(defaultValue = "false")
         boolean includeDeleted,
     @ApiParam(value = "Max records to return", required = false)
         @RequestParam(defaultValue = "100")
         int count)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "listUsers", LOGGER);
   try {
     List<User> usersConv = new ArrayList<User>();
     UserSearchCriteria criteria = new UserSearchCriteria();
     criteria.setIncludeDeleted(includeDeleted);
     List<IUser> users = SiteWhere.getServer().getUserManagement().listUsers(criteria);
     for (IUser user : users) {
       usersConv.add(User.copy(user));
     }
     SearchResults<User> results = new SearchResults<User>(usersConv);
     return results;
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #11
0
  /**
   * Display page for choosing tenant.
   *
   * @param redirect
   * @param servletRequest
   * @return
   */
  @RequestMapping("/tenant")
  public ModelAndView showTenantChoices(
      @RequestParam(required = false) String redirect, HttpServletRequest servletRequest) {
    Tracer.start(TracerCategory.AdminUserInterface, "showTenantChoices", LOGGER);
    try {
      if ((SecurityContextHolder.getContext() == null)
          || (SecurityContextHolder.getContext().getAuthentication() == null)) {
        return login();
      }

      // Find tenants the logged in user is able to view.
      IUser user = LoginManager.getCurrentlyLoggedInUser();
      List<ITenant> matches = SiteWhere.getServer().getAuthorizedTenants(user.getUsername());
      if (matches.size() == 0) {
        return showError("User is not authorized to access any of the available tenants.");
      } else if (matches.size() == 1) {
        // If no redirect specified, show server info page.
        if (redirect == null) {
          redirect = "server.html";
        }
        setChosenTenant(matches.get(0), servletRequest);
        return new ModelAndView("redirect:" + redirect);
      }

      Map<String, Object> data = new HashMap<String, Object>();
      data.put(DATA_VERSION, VersionHelper.getVersion());
      data.put(DATA_CURRENT_USER, LoginManager.getCurrentlyLoggedInUser());
      data.put(DATA_REDIRECT, redirect);
      return new ModelAndView("tenant", data);
    } catch (SiteWhereException e) {
      return showError(e);
    } finally {
      Tracer.stop(LOGGER);
    }
  }
コード例 #12
0
 /**
  * Display the "login" page after failed login.
  *
  * @return
  */
 @RequestMapping("/loginFailed")
 public ModelAndView loginFailed() {
   Tracer.start(TracerCategory.AdminUserInterface, "loginFailed", LOGGER);
   try {
     Map<String, Object> data = new HashMap<String, Object>();
     data.put(DATA_VERSION, VersionHelper.getVersion());
     data.put("loginFailed", true);
     return new ModelAndView("login", data);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #13
0
 /**
  * Display the "list scheduled jobs" page.
  *
  * @param request
  * @return
  */
 @RequestMapping("/jobs/list")
 public ModelAndView listScheduledjobs(HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "listScheduledjobs", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     return new ModelAndView("jobs/list", data);
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #14
0
 /**
  * Update an existing user.
  *
  * @param input
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{username}", method = RequestMethod.PUT)
 @ResponseBody
 @ApiOperation(value = "Update an existing user.")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public User updateUser(
     @ApiParam(value = "Unique username", required = true) @PathVariable String username,
     @RequestBody UserCreateRequest input)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "updateUser", LOGGER);
   try {
     IUser user = SiteWhere.getServer().getUserManagement().updateUser(username, input);
     return User.copy(user);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #15
0
 /**
  * Display the "login" page.
  *
  * @return
  */
 @RequestMapping("/")
 public ModelAndView login() {
   Tracer.start(TracerCategory.AdminUserInterface, "login", LOGGER);
   try {
     Map<String, Object> data = new HashMap<String, Object>();
     data.put(DATA_VERSION, VersionHelper.getVersion());
     if (SiteWhere.getServer().getLifecycleStatus() == LifecycleStatus.Started) {
       return new ModelAndView("login", data);
     } else {
       ServerStartupException failure = SiteWhere.getServer().getServerStartupError();
       data.put("subsystem", failure.getDescription());
       data.put("component", failure.getComponent().getLifecycleError().getMessage());
       return new ModelAndView("noserver", data);
     }
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #16
0
 /**
  * Delete information for a given user based on username.
  *
  * @param siteToken
  * @param force
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{username}", method = RequestMethod.DELETE)
 @ResponseBody
 @ApiOperation(value = "Delete a user by unique username")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public User deleteUserByUsername(
     @ApiParam(value = "Unique username", required = true) @PathVariable String username,
     @ApiParam(value = "Delete permanently", required = false)
         @RequestParam(defaultValue = "false")
         boolean force)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "deleteUserByUsername", LOGGER);
   try {
     IUser user = SiteWhere.getServer().getUserManagement().deleteUser(username, force);
     return User.copy(user);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #17
0
 /**
  * Get a user by unique username.
  *
  * @param username
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{username}", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "Find user by unique username")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public User getUserByUsername(
     @ApiParam(value = "Unique username", required = true) @PathVariable String username)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "getUserByUsername", LOGGER);
   try {
     IUser user = SiteWhere.getServer().getUserManagement().getUserByUsername(username);
     if (user == null) {
       throw new SiteWhereSystemException(
           ErrorCode.InvalidUsername, ErrorLevel.ERROR, HttpServletResponse.SC_NOT_FOUND);
     }
     return User.copy(user);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #18
0
 /**
  * Display the "category person assets" page.
  *
  * @param categoryId
  * @param request
  * @return
  */
 @RequestMapping("/assets/categories/{categoryId}")
 public ModelAndView listCategoryAssets(
     @PathVariable("categoryId") String categoryId, HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "listCategoryAssets", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     ITenant tenant = (ITenant) data.get(DATA_TENANT);
     IAssetCategory category =
         SiteWhere.getServer().getAssetManagement(tenant).getAssetCategory(categoryId);
     data.put("category", category);
     return new ModelAndView("assets/categoryAssets", data);
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #19
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);
   }
 }
コード例 #20
0
 /**
  * Get a list of detailed authority information for a given user.
  *
  * @param username
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{username}/authorities", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "Find authorities assigned to a given user")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public SearchResults<GrantedAuthority> getAuthoritiesForUsername(
     @ApiParam(value = "Unique username", required = true) @PathVariable String username)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "getAuthoritiesForUsername", LOGGER);
   try {
     List<IGrantedAuthority> matches =
         SiteWhere.getServer().getUserManagement().getGrantedAuthorities(username);
     List<GrantedAuthority> converted = new ArrayList<GrantedAuthority>();
     for (IGrantedAuthority auth : matches) {
       converted.add(GrantedAuthority.copy(auth));
     }
     return new SearchResults<GrantedAuthority>(converted);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #21
0
 /**
  * Get a tenant by unique authentication token.
  *
  * @param authToken
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/authtoken/{authToken}", method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "Get tenant by authentication token")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Response,
           json = Tenants.CreateTenantResponse.class,
           description = "getTenantByAuthTokenResponse.md")
     })
 public ITenant getTenantByAuthToken(
     @ApiParam(value = "Authentication token", required = true) @PathVariable String authToken)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "getTenantByAuthToken", LOGGER);
   try {
     return SiteWhere.getServer().getUserManagement().getTenantByAuthenticationToken(authToken);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #22
0
  @RequestMapping("/tenant/{tenantId}")
  public ModelAndView chooseTenant(
      @PathVariable("tenantId") String tenantId,
      @RequestParam(required = false) String redirect,
      HttpServletRequest servletRequest) {
    Tracer.start(TracerCategory.AdminUserInterface, "chooseTenant", LOGGER);
    try {
      if ((SecurityContextHolder.getContext() == null)
          || (SecurityContextHolder.getContext().getAuthentication() == null)) {
        return login();
      }

      // If no redirect specified, show server info page.
      if ((redirect == null) || (redirect.length() == 0)) {
        redirect = "../server.html";
      }

      // Find tenants the logged in user is able to view.
      IUser user = LoginManager.getCurrentlyLoggedInUser();
      List<ITenant> matches = SiteWhere.getServer().getAuthorizedTenants(user.getUsername());
      ITenant chosen = null;
      for (ITenant tenant : matches) {
        if (tenant.getId().equals(tenantId)) {
          chosen = tenant;
        }
      }

      // Trying to choose an invalid or unauthorized tenant.
      if (chosen == null) {
        return showError("Invalid tenant choice.");
      }

      setChosenTenant(chosen, servletRequest);
      return new ModelAndView("redirect:" + redirect);
    } catch (SiteWhereException e) {
      return showError(e);
    } finally {
      Tracer.stop(LOGGER);
    }
  }
コード例 #23
0
 /**
  * Display the "specification detail" page.
  *
  * @param token
  * @param request
  * @return
  */
 @RequestMapping("/specifications/{token}")
 public ModelAndView specificationDetail(
     @PathVariable("token") String token, HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "specificationDetail", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     ITenant tenant = (ITenant) data.get(DATA_TENANT);
     IDeviceManagement management = SiteWhere.getServer().getDeviceManagement(tenant);
     IDeviceSpecification spec = management.getDeviceSpecificationByToken(token);
     if (spec != null) {
       data.put("specification", spec);
       return new ModelAndView("specifications/detail", data);
     }
     return showError("Specification for token '" + token + "' not found.");
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #24
0
 /**
  * Display the "device group detail" page.
  *
  * @param groupToken
  * @param request
  * @return
  */
 @RequestMapping("/groups/{groupToken}")
 public ModelAndView deviceGroupDetail(
     @PathVariable("groupToken") String groupToken, HttpServletRequest request) {
   Tracer.start(TracerCategory.AdminUserInterface, "deviceGroupDetail", LOGGER);
   try {
     Map<String, Object> data = createBaseData(request);
     ITenant tenant = (ITenant) data.get(DATA_TENANT);
     IDeviceManagement management = SiteWhere.getServer().getDeviceManagement(tenant);
     IDeviceGroup group = management.getDeviceGroup(groupToken);
     if (group != null) {
       data.put("group", group);
       return new ModelAndView("groups/detail", data);
     }
     return showError("Device group for token '" + groupToken + "' not found.");
   } catch (NoTenantException e) {
     return showTenantChoices(getUrl(request), request);
   } catch (SiteWhereException e) {
     return showError(e);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #25
0
 /**
  * Create a new user.
  *
  * @param input
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(method = RequestMethod.POST)
 @ResponseBody
 @ApiOperation(value = "Create a new user")
 @Secured({SitewhereRoles.ROLE_ADMINISTER_USERS})
 public User createUser(@RequestBody UserCreateRequest input) throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "createUser", LOGGER);
   try {
     if ((input.getUsername() == null)
         || (input.getPassword() == null)
         || (input.getFirstName() == null)
         || (input.getLastName() == null)) {
       throw new SiteWhereSystemException(ErrorCode.InvalidUserInformation, ErrorLevel.ERROR);
     }
     if (input.getStatus() == null) {
       input.setStatus(AccountStatus.Active);
     }
     IUser user = SiteWhere.getServer().getUserManagement().createUser(input);
     return User.copy(user);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #26
0
 /**
  * Create a new tenant.
  *
  * @param request
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(method = RequestMethod.POST)
 @ResponseBody
 @ApiOperation(value = "Create new tenant")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Request,
           json = Tenants.CreateTenantRequest.class,
           description = "createTenantRequest.md"),
       @Example(
           stage = Stage.Response,
           json = Tenants.CreateTenantResponse.class,
           description = "createTenantResponse.md")
     })
 public ITenant createTenant(@RequestBody TenantCreateRequest request) throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "createTenant", LOGGER);
   try {
     return SiteWhere.getServer().getUserManagement().createTenant(request);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #27
0
 /**
  * Delete tenant by unique tenant id.
  *
  * @param tenantId
  * @param force
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(value = "/{tenantId}", method = RequestMethod.DELETE)
 @ResponseBody
 @ApiOperation(value = "Delete existing tenant")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Response,
           json = Tenants.CreateTenantResponse.class,
           description = "deleteTenantByIdResponse.md")
     })
 public ITenant deleteTenantById(
     @ApiParam(value = "Tenant id", required = true) @PathVariable String tenantId,
     @ApiParam(value = "Delete permanently", required = false)
         @RequestParam(defaultValue = "false")
         boolean force)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "deleteTenantById", LOGGER);
   try {
     return SiteWhere.getServer().getUserManagement().deleteTenant(tenantId, force);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #28
0
 /**
  * List tenants that match the given criteria.
  *
  * @param criteria
  * @return
  * @throws SiteWhereException
  */
 @RequestMapping(method = RequestMethod.GET)
 @ResponseBody
 @ApiOperation(value = "List tenants that match criteria")
 @PreAuthorize(value = SiteWhereRoles.PREAUTH_REST_AND_TENANT_ADMIN)
 @Documented(
     examples = {
       @Example(
           stage = Stage.Response,
           json = Tenants.ListTenantsResponse.class,
           description = "listTenantsResponse.md")
     })
 public ISearchResults<ITenant> listTenants(
     @ApiParam(value = "Authorized user id", required = false) @RequestParam(required = false)
         String authUserId,
     @ApiParam(value = "Include runtime info", required = false)
         @RequestParam(required = false, defaultValue = "false")
         boolean includeRuntimeInfo,
     @ApiParam(value = "Page number", required = false)
         @RequestParam(required = false, defaultValue = "1")
         @Concerns(values = {ConcernType.Paging})
         int page,
     @ApiParam(value = "Page size", required = false)
         @RequestParam(required = false, defaultValue = "100")
         @Concerns(values = {ConcernType.Paging})
         int pageSize)
     throws SiteWhereException {
   Tracer.start(TracerCategory.RestApiCall, "listTenants", LOGGER);
   try {
     TenantSearchCriteria criteria = new TenantSearchCriteria(page, pageSize);
     criteria.setUserId(authUserId);
     criteria.setIncludeRuntimeInfo(includeRuntimeInfo);
     return SiteWhere.getServer().getUserManagement().listTenants(criteria);
   } finally {
     Tracer.stop(LOGGER);
   }
 }
コード例 #29
0
  /**
   * Display the "list devices" page.
   *
   * @param specification
   * @param group
   * @param groupsWithRole
   * @param dateRange
   * @param beforeDate
   * @param afterDate
   * @param excludeAssigned
   * @param request
   * @return
   */
  @RequestMapping("/devices/list")
  public ModelAndView listDevices(
      @RequestParam(required = false) String specification,
      @RequestParam(required = false) String group,
      @RequestParam(required = false) String groupsWithRole,
      @RequestParam(required = false) String site,
      @RequestParam(required = false) String dateRange,
      @RequestParam(required = false) String beforeDate,
      @RequestParam(required = false) String afterDate,
      @RequestParam(required = false) boolean excludeAssigned,
      HttpServletRequest request) {
    Tracer.start(TracerCategory.AdminUserInterface, "listDevices", LOGGER);
    try {
      Map<String, Object> data = createBaseData(request);
      ITenant tenant = (ITenant) data.get(DATA_TENANT);

      // Look up specification that will be used for filtering.
      if (specification != null) {
        IDeviceSpecification found =
            SiteWhere.getServer()
                .getDeviceManagement(tenant)
                .getDeviceSpecificationByToken(specification);
        if (found == null) {
          throw new SiteWhereException("Specification token was not valid.");
        }
        data.put("specification", found);
      }

      // Look up device group that will be used for filtering.
      if (group != null) {
        IDeviceGroup found =
            SiteWhere.getServer().getDeviceManagement(tenant).getDeviceGroup(group);
        if (found == null) {
          throw new SiteWhereException("Device group token was not valid.");
        }
        data.put("group", found);
      }

      if (groupsWithRole != null) {
        data.put("groupsWithRole", groupsWithRole);
      }

      // Look up device group that will be used for filtering.
      if (site != null) {
        ISite found = SiteWhere.getServer().getDeviceManagement(tenant).getSiteByToken(site);
        if (found == null) {
          throw new SiteWhereException("Site token was not valid.");
        }
        data.put("site", found);
      }

      data.put("dateRange", dateRange);
      data.put("beforeDate", beforeDate);
      data.put("afterDate", afterDate);
      data.put("excludeAssigned", excludeAssigned);
      return new ModelAndView("devices/list", data);
    } catch (NoTenantException e) {
      return showTenantChoices(getUrl(request), request);
    } catch (SiteWhereException e) {
      return showError(e);
    } finally {
      Tracer.stop(LOGGER);
    }
  }