code: public static LockedExternalTaskImpl fromEntity(ExternalTaskEntity externalTaskEntity, List<String> variablesToFetch, boolean isLocal, boolean deserializeVariables) {
      LockedExternalTaskImpl result = new LockedExternalTaskImpl();
      result.id = externalTaskEntity.getId();
      result.topicName = externalTaskEntity.getTopicName();
      result.workerId = externalTaskEntity.getWorkerId();
      result.lockExpirationTime = externalTaskEntity.getLockExpirationTime();
      result.retries = externalTaskEntity.getRetries();
      result.errorMessage = externalTaskEntity.getErrorMessage();
      result.errorDetails = externalTaskEntity.getErrorDetails();
  
      result.processInstanceId = externalTaskEntity.getProcessInstanceId();
      result.executionId = externalTaskEntity.getExecutionId();
      result.activityId = externalTaskEntity.getActivityId();
      result.activityInstanceId = externalTaskEntity.getActivityInstanceId();
      result.processDefinitionId = externalTaskEntity.getProcessDefinitionId();
      result.processDefinitionKey = externalTaskEntity.getProcessDefinitionKey();
      result.tenantId = externalTaskEntity.getTenantId();
      result.priority = externalTaskEntity.getPriority();
      result.businessKey = externalTaskEntity.getBusinessKey();
  
      ExecutionEntity execution = externalTaskEntity.getExecution();
      result.variables = new VariableMapImpl();
      execution.collectVariables(result.variables, variablesToFetch, isLocal, deserializeVariables);
  
      return result;
    }
docs: Construct representation of locked ExternalTask from corresponding entity.
  During mapping variables will be collected,during collection variables will not be deserialized
  and scope will not be set to local.
  
  @see {@link org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope#collectVariables(VariableMapImpl, Collection, boolean, boolean)}
  
  @param externalTaskEntity - source persistent entity to use for fields
  @param variablesToFetch - list of variable names to fetch, if null then all variables will be fetched
  @param isLocal - if true only local variables will be collected
  
  @return object with all fields copied from the ExternalTaskEntity, error details fetched from the
  database and variables attached