Пример #1
0
  /**
   * Update Status of the lock operation.
   *
   * @param status Status of the operation.
   * @param syncmlDocument parsed syncml payload.
   * @param deviceIdentifier Device Id.
   * @throws OperationManagementException
   * @throws DeviceManagementException
   * @throws NotificationManagementException
   */
  public void lockOperationUpdate(
      StatusTag status, SyncmlDocument syncmlDocument, DeviceIdentifier deviceIdentifier)
      throws OperationManagementException, DeviceManagementException,
          NotificationManagementException {

    pendingDataOperations =
        WindowsAPIUtils.getDeviceManagementService()
            .getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
    if (Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData())) {
      for (Operation operation : pendingDataOperations) {
        if ((OperationCode.Command.DEVICE_LOCK.getCode().equals(operation.getCode()))
            && operation.getId() == status.getCommandReference()) {
          operation.setStatus(Operation.Status.COMPLETED);
          new OperationUtils()
              .updateOperations(
                  syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
        }
      }
    }
    if (Constants.SyncMLResponseCodes.PIN_NOTFOUND.equals(status.getData())) {
      for (Operation operation : pendingDataOperations) {

        if ((OperationCode.Command.DEVICE_LOCK.getCode().equals(operation.getCode())
            && operation.getId() == status.getCommandReference())) {
          operation.setStatus(Operation.Status.ERROR);
          new OperationUtils()
              .updateOperations(
                  syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
          try {
            NotificationManagementService nmService =
                WindowsAPIUtils.getNotificationManagementService();
            Notification lockResetNotification = new Notification();
            lockResetNotification.setOperationId(status.getCommandReference());
            lockResetNotification.setStatus(String.valueOf(Notification.Status.NEW));
            lockResetNotification.setDeviceIdentifier(deviceIdentifier);
            lockResetNotification.setDescription(
                Constants.SyncMLResponseCodes.LOCKRESET_NOTIFICATION);

            nmService.addNotification(lockResetNotification);
          } catch (NotificationManagementException e) {
            String msg = "Failure occurred in getting notification service";
            log.error(msg, e);
            throw new NotificationManagementException(msg, e);
          }
        }
      }
    }
  }
Пример #2
0
  /**
   * Generate status of the features that have been activated on the device.
   *
   * @param syncmlDocument syncmlDocument object pasrsed from the syncml engine.
   * @return device statuses for the activated features
   * @throws NotificationManagementException
   */
  public List<Profile> generateDeviceOperationStatusObject(SyncmlDocument syncmlDocument)
      throws NotificationManagementException, WindowsOperationException {

    DeviceIdentifier deviceIdentifier =
        convertToDeviceIdentifierObject(syncmlDocument.getHeader().getSource().getLocURI());
    String lockUri = null;
    ResultsTag result = syncmlDocument.getBody().getResults();

    List<Profile> profiles = new ArrayList<>();
    if (result != null) {
      List<ItemTag> results = result.getItem();
      for (OperationCode.Info info : OperationCode.Info.values()) {
        if (PluginConstants.OperationCodes.PIN_CODE.equals(info.name())) {
          lockUri = info.getCode();
        }
      }
      for (ItemTag item : results) {
        for (OperationCode.Info info : OperationCode.Info.values()) {
          if (item.getSource().getLocURI().equals(info.getCode())
              && PluginConstants.OperationCodes.CAMERA_STATUS.equals(info.name())) {
            Profile cameraProfile = new Profile();
            cameraProfile.setFeatureCode(PluginConstants.OperationCodes.CAMERA);
            cameraProfile.setData(item.getData());
            if ((PluginConstants.SyncML.SYNCML_DATA_ONE.equals(item.getData()))) {
              cameraProfile.setEnable(true);
            } else {
              cameraProfile.setEnable(false);
            }
            profiles.add(cameraProfile);
          }
          if (item.getSource().getLocURI().equals(info.getCode())
              && PluginConstants.OperationCodes.ENCRYPT_STORAGE_STATUS.equals(info.name())) {
            Profile encryptStorage = new Profile();
            encryptStorage.setFeatureCode(PluginConstants.OperationCodes.ENCRYPT_STORAGE);
            encryptStorage.setData(item.getData());
            if ((PluginConstants.SyncML.SYNCML_DATA_ONE.equals(item.getData()))) {
              encryptStorage.setEnable(true);
            } else {
              encryptStorage.setEnable(false);
            }
            profiles.add(encryptStorage);
          }
          if (item.getSource().getLocURI().equals(info.getCode())
              && PluginConstants.OperationCodes.DEVICE_PASSWORD_STATUS.equals(info.name())) {
            Profile encryptStorage = new Profile();
            encryptStorage.setFeatureCode(PluginConstants.OperationCodes.PASSCODE_POLICY);
            encryptStorage.setData(item.getData());
            if ((PluginConstants.SyncML.SYNCML_DATA_ZERO.equals(item.getData()))) {
              encryptStorage.setEnable(true);
            } else {
              encryptStorage.setEnable(false);
            }
            profiles.add(encryptStorage);
          }
          if (!item.getData().isEmpty() && item.getSource().getLocURI().equals(lockUri)) {
            String pinValue = item.getData();
            NotificationManagementService nmService =
                WindowsAPIUtils.getNotificationManagementService();
            Notification notification = new Notification();
            notification.setDescription("Auto generated DevicePin : " + pinValue);
            notification.setOperationId(result.getCommandReference());
            notification.setDeviceIdentifier(deviceIdentifier);
            notification.setStatus(String.valueOf(Notification.Status.NEW));
            try {
              nmService.addNotification(notification);
            } catch (NotificationManagementException e) {
              String msg = "Failure Occurred in getting notification service.";
              log.error(msg, e);
              throw new WindowsOperationException(msg, e);
            }
            break;
          }
        }
      }
    }
    return profiles;
  }