private BinaryVariable getBinaryVariable(long taskInstanceId, Integer binaryVariableHash) {

    List<BinaryVariable> variables = getVariablesHandler().resolveBinaryVariables(taskInstanceId);

    for (BinaryVariable binaryVariable : variables) {

      if (binaryVariable.getHash().equals(binaryVariableHash)) {

        return binaryVariable;
      }
    }

    return null;
  }
  public void execute(ExecutionContext executionContext) throws Exception {
    TaskInstanceW taskInstanceW =
        getBpmFactory()
            .getProcessManagerByTaskInstanceId(getTaskInstanceId())
            .getTaskInstance(getTaskInstanceId());

    Object obj = taskInstanceW.getVariable(getSelectedAttachementVariableName());

    Variable variable =
        Variable.parseDefaultStringRepresentation(getAddedAttachmentsVariableName());

    if (obj instanceof List) {
      @SuppressWarnings("unchecked")
      List<String> variablesList = (List<String>) obj;
      for (String str : variablesList) {
        String taskInstnaceId = str.substring(0, str.indexOf(";"));
        String variableHash = str.substring(str.indexOf(";") + 1, str.length());
        BinaryVariable binaryVariable =
            getBinaryVariable(Long.valueOf(taskInstnaceId), Integer.valueOf(variableHash));

        BinaryVariable addedAttachment =
            taskInstanceW.addAttachment(
                variable,
                binaryVariable.getFileName(),
                binaryVariable.getDescription(),
                getVariablesHandler()
                    .getBinaryVariablesHandler()
                    .getBinaryVariableContent(binaryVariable));

        // TODO: what really should be copied and what shoud not?
        addedAttachment.setMetadata(binaryVariable.getMetadata());
        addedAttachment.setSigned(binaryVariable.getSigned());
        addedAttachment.update();
      }
    }
  }