예제 #1
0
  /**
   * Update the completed/Error status of the operation which have the URI of the operation code in
   * the syncml payload.
   *
   * @param syncmlDocument SyncmlDocument object generated from the the syncml engine.
   * @throws DeviceManagementException
   * @throws NotificationManagementException
   * @throws OperationManagementException
   */
  public void UpdateUriOperations(SyncmlDocument syncmlDocument)
      throws DeviceManagementException, NotificationManagementException,
          OperationManagementException, WindowsOperationException {
    DeviceIdentifier deviceIdentifier =
        convertToDeviceIdentifierObject(syncmlDocument.getHeader().getSource().getLocURI());
    List<StatusTag> statuses = syncmlDocument.getBody().getStatus();
    OperationUtils operationUtils = new OperationUtils();

    for (StatusTag status : statuses) {

      if ((Constants.EXECUTE.equals(status.getCommand()))) {
        if (status.getTargetReference() == null) {
          operationUtils.updateDeviceOperations(status, syncmlDocument, deviceIdentifier);
        } else {
          if ((OperationCode.Command.DEVICE_LOCK.equals(status.getTargetReference()))) {
            operationUtils.lockOperationUpdate(status, syncmlDocument, deviceIdentifier);
          }
          if ((OperationCode.Command.DEVICE_RING.equals(status.getTargetReference()))) {
            operationUtils.ring(status, syncmlDocument, deviceIdentifier);
          }
          if (equals(OperationCode.Command.WIPE_DATA.equals(status.getTargetReference()))) {
            operationUtils.dataWipe(status, syncmlDocument, deviceIdentifier);
          }
        }
      }
      if ((Constants.SEQUENCE.equals(status.getCommand()))) {
        if ((Constants.SyncMLResponseCodes.ACCEPTED.equals(status.getData()))) {

          pendingDataOperations =
              WindowsAPIUtils.getDeviceManagementService()
                  .getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
          for (Operation operation : pendingDataOperations) {
            if ((PluginConstants.OperationCodes.POLICY_BUNDLE.equals(operation.getCode()))
                && operation.getId() == status.getCommandReference()) {
              operation.setStatus(Operation.Status.COMPLETED);
            }
            if ((PluginConstants.OperationCodes.MONITOR.equals(operation.getCode()))
                && operation.getId() == status.getCommandReference()) {
              operation.setStatus(Operation.Status.COMPLETED);
            }
          }
          operationUtils.updateOperations(
              syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
        } else {
          pendingDataOperations =
              WindowsAPIUtils.getDeviceManagementService()
                  .getOperationsByDeviceAndStatus(deviceIdentifier, Operation.Status.PENDING);
          for (Operation operation : pendingDataOperations) {

            if ((PluginConstants.OperationCodes.POLICY_BUNDLE.equals(operation.getCode()))
                && operation.getId() == status.getCommandReference()) {
              operation.setStatus(Operation.Status.ERROR);
            }
            if ((PluginConstants.OperationCodes.MONITOR.equals(operation.getCode()))
                && operation.getId() == status.getCommandReference()) {
              operation.setStatus(Operation.Status.ERROR);
            }
          }
          operationUtils.updateOperations(
              syncmlDocument.getHeader().getSource().getLocURI(), pendingDataOperations);
        }
      }
    }
  }
예제 #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;
  }
예제 #3
0
  private SyncmlBody generateStatuses() {
    SyncmlBody sourceSyncmlBody = syncmlDocument.getBody();
    SyncmlHeader sourceHeader = syncmlDocument.getHeader();
    SyncmlBody syncmlBodyReply = new SyncmlBody();
    List<Status> status = new ArrayList<Status>();
    Status headerStatus =
        new Status(
            HEADER_COMMAND_REFERENCE_ID,
            sourceHeader.getMsgID(),
            HEADER_STATUS_ID,
            HEADER_COMMAND_TEXT,
            sourceHeader.getSource().getLocURI(),
            String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED));
    status.add(headerStatus);
    if (sourceSyncmlBody.getAlert() != null) {
      Status alertStatus =
          new Status(
              sourceSyncmlBody.getAlert().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getAlert().getCommandId(),
              ALERT_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(alertStatus);
    }
    if (sourceSyncmlBody.getReplace() != null) {
      Status replaceStatus =
          new Status(
              sourceSyncmlBody.getReplace().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getReplace().getCommandId(),
              REPLACE_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(replaceStatus);
    }
    if (sourceSyncmlBody.getExec() != null) {
      Status replaceStatus =
          new Status(
              sourceSyncmlBody.getExec().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getExec().getCommandId(),
              GET_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(replaceStatus);
    }
    if (sourceSyncmlBody.getGet() != null) {
      Status execStatus =
          new Status(
              sourceSyncmlBody.getGet().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getGet().getCommandId(),
              EXEC_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(execStatus);
    }

    syncmlBodyReply.setStatus(status);
    return syncmlBodyReply;
  }