@Override
 public Activity installApplicationForDevices(
     Operation operation, List<DeviceIdentifier> deviceIds) throws ApplicationManagementException {
   try {
     // TODO: Fix this properly later adding device type to be passed in when the task manage
     // executes "addOperations()"
     String type = null;
     if (deviceIds.size() > 0) {
       type = deviceIds.get(0).getType().toLowerCase();
     }
     Activity activity =
         DeviceManagementDataHolder.getInstance()
             .getDeviceManagementProvider()
             .addOperation(type, operation, deviceIds);
     DeviceManagementDataHolder.getInstance()
         .getDeviceManagementProvider()
         .notifyOperationToDevices(operation, deviceIds);
     return activity;
   } catch (OperationManagementException e) {
     throw new ApplicationManagementException("Error in add operation at app installation", e);
   } catch (DeviceManagementException e) {
     throw new ApplicationManagementException("Error in notify operation at app installation", e);
   } catch (InvalidDeviceException e) {
     throw new ApplicationManagementException("Invalid DeviceIdentifiers found.", e);
   }
 }
  @Override
  public void addOperations() throws DeviceMgtTaskException {

    DeviceManagementProviderService deviceManagementProviderService =
        DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
    try {
      List<Device> devices = deviceManagementProviderService.getAllDevices();
      List<String> operations = this.getValidOperationNames();

      if (!devices.isEmpty()) {

        for (String str : operations) {
          CommandOperation operation = new CommandOperation();
          operation.setEnabled(true);
          operation.setType(Operation.Type.COMMAND);
          operation.setCode(str);
          deviceManagementProviderService.addOperation(
              operation, DeviceManagerUtil.convertDevices(devices));
        }
      } else {
        if (log.isDebugEnabled()) {
          log.debug("No devices are available to perform the operations.");
        }
      }
    } catch (DeviceManagementException e) {
      throw new DeviceMgtTaskException("Error occurred while retrieving the device list.", e);
    } catch (OperationManagementException e) {
      throw new DeviceMgtTaskException("Error occurred while adding the operations to devices", e);
    }
  }
  @Override
  public Activity installApplicationForUsers(Operation operation, List<String> userNameList)
      throws ApplicationManagementException {

    String userName = null;
    try {
      List<Device> deviceList;
      List<DeviceIdentifier> deviceIdentifierList = new ArrayList<>();
      DeviceIdentifier deviceIdentifier;

      for (String user : userNameList) {
        userName = user;
        deviceList =
            DeviceManagementDataHolder.getInstance()
                .getDeviceManagementProvider()
                .getDevicesOfUser(user);
        for (Device device : deviceList) {
          deviceIdentifier = new DeviceIdentifier();
          deviceIdentifier.setId(Integer.toString(device.getId()));
          deviceIdentifier.setType(device.getType());

          deviceIdentifierList.add(deviceIdentifier);
        }
      }
      // TODO: Fix this properly later adding device type to be passed in when the task manage
      // executes "addOperations()"
      String type = null;
      if (deviceIdentifierList.size() > 0) {
        type = deviceIdentifierList.get(0).getType();
      }

      return DeviceManagementDataHolder.getInstance()
          .getDeviceManagementProvider()
          .addOperation(type, operation, deviceIdentifierList);
    } catch (InvalidDeviceException e) {
      throw new ApplicationManagementException("Invalid DeviceIdentifiers found.", e);
    } catch (DeviceManagementException e) {
      throw new ApplicationManagementException(
          "Error in get devices for user: "******" in app installation", e);

    } catch (OperationManagementException e) {
      throw new ApplicationManagementException("Error in add operation at app installation", e);
    }
  }
 private void initOperationManager() {
   this.operationManager = new OperationManagerImpl();
   DeviceManagementDataHolder.getInstance()
       .setDeviceManagementProvider(new DeviceManagementServiceProviderImpl());
 }