コード例 #1
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);
    }
  }
コード例 #2
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);
   }
 }
コード例 #3
0
 /**
  * Marshals an event to JSON and sends it to EventHub via AMQP.
  *
  * @param event
  * @throws SiteWhereException
  */
 protected void sendEvent(IDeviceEvent event) throws SiteWhereException {
   try {
     BytesMessage message = session.createBytesMessage();
     message.writeBytes(MarshalUtils.marshalJson(event));
     message.setJMSMessageID("ID:" + event.getId());
     sender.send(message);
   } catch (JMSException e) {
     throw new SiteWhereException(e);
   }
 }