コード例 #1
0
  /**
   * @param applicationOperationDevice holds the information needs to retrieve device list.
   * @return List of devices
   * @throws MobileApplicationException
   */
  public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice)
      throws MobileApplicationException {

    List<Device> devices;
    try {
      List<org.wso2.carbon.device.mgt.common.Device> deviceList =
          MDMServiceAPIUtils.getDeviceManagementService(applicationOperationDevice.getTenantId())
              .getDevicesOfUser(applicationOperationDevice.getCurrentUser().getUsername());
      devices = new ArrayList<>(deviceList.size());
      if (log.isDebugEnabled()) {
        log.debug("device list got from mdm " + deviceList.toString());
      }
      for (org.wso2.carbon.device.mgt.common.Device commonDevice : deviceList) {
        if (MDMAppConstants.ACTIVE.equals(
            commonDevice.getEnrolmentInfo().getStatus().toString().toLowerCase())) {
          Device device = new Device();
          org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier deviceIdentifier =
              new org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier();
          deviceIdentifier.setId(commonDevice.getDeviceIdentifier());
          deviceIdentifier.setType(commonDevice.getType());
          device.setDeviceIdentifier(deviceIdentifier);
          device.setName(commonDevice.getName());
          device.setModel(commonDevice.getName());
          device.setType(MDMAppConstants.MOBILE_DEVICE);
          String imgUrl;
          if (MDMAppConstants.ANDROID.equalsIgnoreCase(commonDevice.getType())) {
            imgUrl =
                String.format(
                    applicationOperationDevice.getConfigParams().get(MDMAppConstants.IMAGE_URL),
                    MDMAppConstants.NEXUS);
          } else if (MDMAppConstants.IOS.equalsIgnoreCase(commonDevice.getType())) {
            imgUrl =
                String.format(
                    applicationOperationDevice.getConfigParams().get(MDMAppConstants.IMAGE_URL),
                    MDMAppConstants.IPHONE);
          } else {
            imgUrl =
                String.format(
                    applicationOperationDevice.getConfigParams().get(MDMAppConstants.IMAGE_URL),
                    MDMAppConstants.NONE);
          }
          device.setImage(imgUrl);
          device.setPlatform(commonDevice.getType());
          devices.add(device);
        }
      }
    } catch (DeviceManagementException e) {
      logError("Error While retrieving Device List.", e);
      throw new MobileApplicationException(e.getMessage());
    }
    return devices;
  }
 public boolean addDevice(Device device) throws DigitalDisplayDeviceMgtPluginException {
   boolean status = false;
   Connection conn = null;
   PreparedStatement stmt = null;
   try {
     conn = DigitalDisplayDAO.getConnection();
     String createDBQuery =
         "INSERT INTO DIGITAL_DISPLAY_DEVICE(DIGITAL_DISPLAY_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
     stmt = conn.prepareStatement(createDBQuery);
     stmt.setString(1, device.getDeviceIdentifier());
     stmt.setString(2, device.getName());
     int rows = stmt.executeUpdate();
     if (rows > 0) {
       status = true;
       if (log.isDebugEnabled()) {
         log.debug(
             "Digital Display device "
                 + device.getDeviceIdentifier()
                 + " data has been"
                 + " added to the Digital Display database.");
       }
     }
   } catch (SQLException e) {
     String msg =
         "Error occurred while adding the Digital Display device '"
             + device.getDeviceIdentifier()
             + "' to the Digital Display db.";
     log.error(msg, e);
     throw new DigitalDisplayDeviceMgtPluginException(msg, e);
   } finally {
     DigitalDisplayUtils.cleanupResources(stmt, null);
   }
   return status;
 }
 public boolean updateDevice(Device device) throws DigitalDisplayDeviceMgtPluginException {
   boolean status = false;
   Connection conn = null;
   PreparedStatement stmt = null;
   try {
     conn = DigitalDisplayDAO.getConnection();
     String updateDBQuery =
         "UPDATE DIGITAL_DISPLAY_DEVICE SET  DEVICE_NAME = ? WHERE DIGITAL_DISPLAY_DEVICE_ID = ?";
     stmt = conn.prepareStatement(updateDBQuery);
     stmt.setString(1, device.getName());
     stmt.setString(2, device.getDeviceIdentifier());
     int rows = stmt.executeUpdate();
     if (rows > 0) {
       status = true;
       if (log.isDebugEnabled()) {
         log.debug(
             "Digital Display device "
                 + device.getDeviceIdentifier()
                 + " data has been"
                 + " modified.");
       }
     }
   } catch (SQLException e) {
     String msg =
         "Error occurred while modifying the Digital Display device '"
             + device.getDeviceIdentifier()
             + "' data.";
     log.error(msg, e);
     throw new DigitalDisplayDeviceMgtPluginException(msg, e);
   } finally {
     DigitalDisplayUtils.cleanupResources(stmt, null);
   }
   return status;
 }