/*
   * (non-Javadoc)
   *
   * @see
   * org.talend.core.model.migration.TXMLMapChangeAllInOneValueMigrationTask
   * (org .talend.core.model.properties.Item)
   */
  @Override
  public ExecutionResult execute(Item item) {

    IProxyRepositoryFactory factory =
        CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;

    if (processType != null) {
      for (Object obj : processType.getNode()) {
        NodeType nodeType = (NodeType) obj;
        if (nodeType.getComponentName().startsWith("tXMLMap")) {
          XmlMapData xmlMapdata = (XmlMapData) nodeType.getNodeData();
          EList<OutputXmlTree> outputTables = xmlMapdata.getOutputTrees();
          EList<InputXmlTree> inputTables = xmlMapdata.getInputTrees();
          boolean hasDocumentInTheMainInputTable = false;
          for (InputXmlTree inputTable : inputTables) {
            if (!(inputTable.isLookup())) {
              for (TreeNode inputEntry : inputTable.getNodes()) {
                if ("id_Document".equals(inputEntry.getType())) {
                  hasDocumentInTheMainInputTable = true;
                }
              }
            }
          }
          if (hasDocumentInTheMainInputTable) {
            for (OutputXmlTree outputTable : outputTables) {
              for (TreeNode outputEntry : outputTable.getNodes()) {
                if ("id_Document".equals(outputEntry.getType())) {
                  if (!outputTable.isAllInOne()) {
                    outputTable.setAllInOne(true);
                    modified = true;
                    break;
                  }
                }
              }
            }
          }
        }
      }
    }
    try {
      if (modified) {
        factory.save(item, true);
        return ExecutionResult.SUCCESS_WITH_ALERT;
      } else {
        return ExecutionResult.SUCCESS_NO_ALERT;
      }
    } catch (Exception e) {
      ExceptionHandler.process(e);
      return ExecutionResult.FAILURE;
    }
  }