/* (non-Javadoc)
   * @see com.evolveum.midpoint.model.sync.Action#handle(com.evolveum.midpoint.model.lens.LensContext, com.evolveum.midpoint.model.sync.SynchronizationSituation, java.util.Map, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
   */
  @Override
  public <F extends FocusType> void handle(
      LensContext<F> context,
      SynchronizationSituation<F> situation,
      Map<QName, Object> parameters,
      Task task,
      OperationResult parentResult) {
    ActivationStatusType desiredStatus = ActivationStatusType.DISABLED;

    LensProjectionContext projectionContext = context.getProjectionContextsIterator().next();
    PrismObject<ShadowType> objectCurrent = projectionContext.getObjectCurrent();
    if (objectCurrent != null) {
      PrismProperty<Object> administrativeStatusProp =
          objectCurrent.findProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
      if (administrativeStatusProp != null) {
        if (desiredStatus.equals(administrativeStatusProp.getRealValue())) {
          // Desired status already set, nothing to do
          return;
        }
      }
    }
    ObjectDelta<ShadowType> activationDelta =
        ObjectDelta.createModificationReplaceProperty(
            ShadowType.class,
            projectionContext.getOid(),
            SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS,
            getPrismContext(),
            desiredStatus);
    projectionContext.setPrimaryDelta(activationDelta);
  }
  private void updateAccountStatusPerformed(
      AjaxRequestTarget target, AccountContentDto dto, boolean enabled) {
    List<AccountContentDto> accounts = isAnythingSelected(target, dto);
    OperationResult result = new OperationResult(OPERATION_ADJUST_ACCOUNT_STATUS);

    if (accounts.isEmpty()) {
      return;
    }

    ActivationStatusType status =
        enabled ? ActivationStatusType.ENABLED : ActivationStatusType.DISABLED;

    for (AccountContentDto acc : accounts) {

      ObjectDelta delta =
          ObjectDelta.createModificationReplaceProperty(
              ShadowType.class,
              acc.getAccountOid(),
              new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS),
              getPrismContext(),
              status);

      try {
        Task task = createSimpleTask(OPERATION_ADJUST_ACCOUNT_STATUS);
        getModelService()
            .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result);
      } catch (Exception e) {
        LoggingUtils.logException(LOGGER, "Couldn't enable/disable account(s) on resource", e);
        result.recordPartialError("Couldn't enable/disable account(s) on resource", e);
      }
    }
    result.recomputeStatus();
    showResult(result);
    target.add(getFeedbackPanel());
  }