コード例 #1
0
 /** Check whether device model is populated and offer to bootstrap system if not. */
 protected void verifyDeviceModel() {
   try {
     IDeviceModelInitializer init =
         (IDeviceModelInitializer)
             SERVER_SPRING_CONTEXT.getBean(SiteWhereServerBeans.BEAN_DEVICE_MODEL_INITIALIZER);
     ISearchResults<ISite> sites = getDeviceManagement().listSites(new SearchCriteria(1, 1));
     if (sites.getNumResults() == 0) {
       List<String> messages = new ArrayList<String>();
       messages.add(
           "There are currently no sites defined in the system. You have the option of loading "
               + "a default dataset for previewing system functionality. Would you like to load the default "
               + "dataset?");
       String message = StringMessageUtils.getBoilerPlate(messages, '*', 60);
       LOGGER.info("\n" + message + "\n");
       System.out.println("Load default dataset? Yes/No (Default is Yes)");
       String response = readLine();
       if ((response == null) && (init.isInitializeIfNoConsole())) {
         response = "Y";
       } else if ((response == null) && (!init.isInitializeIfNoConsole())) {
         response = "N";
       }
       if ((response.length() == 0) || (response.toLowerCase().startsWith("y"))) {
         init.initialize(getDeviceManagement());
       }
     }
   } catch (NoSuchBeanDefinitionException e) {
     LOGGER.info("No device model initializer found in Spring bean configuration. Skipping.");
     return;
   } catch (SiteWhereException e) {
     LOGGER.warn("Unable to read from device model.", e);
   }
 }
コード例 #2
0
  /**
   * Test API calls for listing and removing group elements.
   *
   * @param group
   * @throws SiteWhereException
   */
  protected void testListAndRemoveNetworkElements(IDeviceGroup group) throws SiteWhereException {
    ISearchResults<IDeviceGroupElement> groupElements =
        getDeviceManagement().listDeviceGroupElements(group.getToken(), new SearchCriteria(0, 10));
    LOGGER.info("Matched " + groupElements.getResults().size() + " group elements.");

    List<IDeviceGroupElementCreateRequest> delete =
        new ArrayList<IDeviceGroupElementCreateRequest>();
    for (IDeviceGroupElement current : groupElements.getResults()) {
      DeviceGroupElementCreateRequest delElm = new DeviceGroupElementCreateRequest();
      delElm.setType(current.getType());
      delElm.setElementId(current.getElementId());
      delete.add(delElm);
    }
    List<IDeviceGroupElement> deleted =
        getDeviceManagement().removeDeviceGroupElements(group.getToken(), delete);
    LOGGER.info("Deleted " + deleted.size() + " group elements.");

    groupElements =
        getDeviceManagement().listDeviceGroupElements(group.getToken(), new SearchCriteria(0, 100));
    LOGGER.info("Remaining was " + groupElements.getResults().size() + " group elements.");
  }