  public boolean execute(Map<ConanParameter, String> parameters)
      throws ProcessExecutionException, IllegalArgumentException,
      InterruptedException {
    int exitValue = 0;
    AccessionParameter accession = new AccessionParameter();
    accession.setAccession(parameters.get(accessionParameter));
    String reportsDir =
        accession.getFile().getParentFile().getAbsolutePath() + File.separator +
            "reports";
    File reportsDirFile = new File(reportsDir);
    if (!reportsDirFile.exists()) {
      reportsDirFile.mkdirs();
    }
    String fileName = reportsDir + File.separator + accession.getAccession() +
        "_AtlasEligibilityCheck" +
        "_" + new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss").format(new Date()) +
        ".report";
    try {
      log = new BufferedWriter(new FileWriter(fileName));
      log.write("Atlas Eligibility Check: START\n");
    }
    catch (IOException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
      "Can't create report file '" + fileName + "'");
      String[] errors = new String[1];
      errors[0] =  "Can't create report file '" + fileName + "'";
      pex.setProcessOutput(errors);
      throw pex;
    }
    MAGETABParser parser = new MAGETABParser();
    try {
      MAGETABInvestigation investigation =
          parser.parse(accession.getFile().getAbsoluteFile());
      boolean isAtlasType = false;
      String restrictedExptType = "";
      if (investigation.IDF.getComments().containsKey("AEExperimentType")) {
        for (String exptType : investigation.IDF.getComments()
            .get("AEExperimentType")) {
          for (String AtlasType : controlledVocabularyDAO
              .getAtlasExperimentTypes()) {
            if (exptType.equals(AtlasType)) {
              isAtlasType = true;
            }
            else {
              restrictedExptType = exptType;
            }
          }
        }
      }
      else {
       for (String exptType : investigation.IDF.experimentalDesign) {
          for (String AtlasType : controlledVocabularyDAO
              .getAtlasExperimentTypes()) {
            if (exptType.equals(AtlasType)) {
              isAtlasType = true;
            }
          }
        }
       }
      if (!isAtlasType)
      {
        exitValue = 1;
        log.write(
            "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas\n");
        System.out.println(
            "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas");
        ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
        "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas");
        String[] errors = new String[1];
        errors[0] = "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas";
        pex.setExceptionCausesAbort();
        pex.setProcessOutput(errors);
        throw pex;
      }
      else {
        if (investigation.SDRF.getNumberOfChannels() > 1) {
          exitValue = 1;
          log.write(
              "Two-channel experiment is not accepted by Atlas\n");
          System.out.println(
              "Two-channel experiment is not accepted by Atlas");
          ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
          "Two-channel experiment is not accepted by Atlas");
          String[] errors = new String[1];
          errors[0] = "Two-channel experiment is not accepted by Atlas";
          pex.setExceptionCausesAbort();
          pex.setProcessOutput(errors);
          throw pex;
        }
        Collection<HybridizationNode> hybridizationNodes =
            investigation.SDRF.getNodes(HybridizationNode.class);
        Collection<ArrayDataNode> rawDataNodes =
            investigation.SDRF.getNodes(ArrayDataNode.class);
        Collection<DerivedArrayDataNode> processedDataNodes =
            investigation.SDRF.getNodes(DerivedArrayDataNode.class);
        Collection<DerivedArrayDataMatrixNode> processedDataMatrixNodes =
            investigation.SDRF.getNodes(DerivedArrayDataMatrixNode.class);
        int factorValues = 0;
        for (HybridizationNode hybNode : hybridizationNodes)
        {
          if (hybNode.factorValues.size() > 0) {
            factorValues++;
          }
          ArrayDesignAccessions.clear();
          for (ArrayDesignAttribute arrayDesign : hybNode.arrayDesigns) {
            if (!ArrayDesignAccessions
                .contains(arrayDesign.getAttributeValue())) {
              ArrayDesignAccessions.add(arrayDesign.getAttributeValue());
            }
          }
        }
        if (factorValues == 0) {
          exitValue = 1;
          log.write(
              "Experiment does not have Factor Values\n");
          System.out.println(
              "Experiment does not have Factor Values");
          ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
          "Experiment does not have Factor Values");
          String[] errors = new String[1];
          errors[0] = "Experiment does not have Factor Values";
          pex.setExceptionCausesAbort();
          pex.setProcessOutput(errors);
          throw pex;
        }
        boolean factorTypesFromCV = true;
        List<String> missedFactorType = new ArrayList<String>();
        for (String factorType : investigation.IDF.experimentalFactorType) {
          if (!controlledVocabularyDAO
              .getAtlasFactorTypes().contains(factorType)) {
            factorTypesFromCV = false;
            missedFactorType.add(factorType);
          }
        }
        if (!factorTypesFromCV) {
          exitValue = 1;
          log.write(
              "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType + "\n");
          System.out.println(
              "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType);
          ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
          "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType);
          String[] errors = new String[1];
          errors[0] = "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType;
          pex.setExceptionCausesAbort();
          pex.setProcessOutput(errors);
          throw pex;
        }
        for (String arrayDesign : ArrayDesignAccessions) {
          ArrayDesignExistenceChecking arrayDesignExistenceChecking =
              new ArrayDesignExistenceChecking();
          String arrayCheckResult =
              arrayDesignExistenceChecking.execute(arrayDesign);
          if (arrayCheckResult.equals("empty") ||
              arrayCheckResult.equals("no")) {
            exitValue = 1;
            log.write("Array design '" +
                          arrayDesign +
                          "' used in experiment is not in Atlas\n");
            System.out.println("Array design '" +
                                   arrayDesign +
                                   "' used in experiment is not in Atlas");
            ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
            "Array design '" +
                                   arrayDesign +
                                   "' used in experiment is not in Atlas");
            String[] errors = new String[1];
            errors[0] = "Array design '" +
                                   arrayDesign +
                                   "' used in experiment is not in Atlas";
            pex.setExceptionCausesAbort();
            pex.setProcessOutput(errors);
            throw pex;
          }
          else {
            Collection<HybridizationNode> hybridizationSubNodes =
                new ArrayList<HybridizationNode>();
            Collection<Node> rawDataSubNodes = new ArrayList<Node>();
            Collection<Node> processedDataSubNodes = new ArrayList<Node>();
            Collection<Node> processedDataMatrixSubNodes =
                new ArrayList<Node>();
            if (ArrayDesignAccessions.size() > 1) {
              for (HybridizationNode hybNode : hybridizationNodes) {
                ArrayDesignAttribute attribute = new ArrayDesignAttribute();
                attribute.setAttributeValue(arrayDesign);
                if (hybNode.arrayDesigns.contains(attribute)) {
                  hybridizationSubNodes.add(hybNode);
                  getNodes(hybNode, ArrayDataNode.class, rawDataSubNodes);
                  getNodes(hybNode, DerivedArrayDataNode.class,
                           processedDataSubNodes);
                  getNodes(hybNode, DerivedArrayDataMatrixNode.class,
                           processedDataMatrixSubNodes);
                }
              }
            }
            else {
              hybridizationSubNodes = hybridizationNodes;
              for (ArrayDataNode node : rawDataNodes) {
                rawDataSubNodes.add(node);
              }
              for (DerivedArrayDataNode node : processedDataNodes) {
                processedDataSubNodes.add(node);
              }
              for (DerivedArrayDataMatrixNode node : processedDataMatrixNodes) {
                processedDataMatrixSubNodes.add(node);
              }
            }
            if (arrayCheckResult.equals("affy") &&
                hybridizationSubNodes.size() != rawDataSubNodes.size())
            {
              exitValue = 1;
              log.write(
                  "Affymetrix experiment without raw data files\n");
              System.out.println(
                  "Affymetrix experiment without raw data files");
              ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
              "Affymetrix experiment without raw data files");
              String[] errors = new String[1];
              errors[0] = "Affymetrix experiment without raw data files";
              pex.setExceptionCausesAbort();
              pex.setProcessOutput(errors);
              throw pex;
            }
            else
              if (processedDataSubNodes.size() == 0 &&
                  processedDataMatrixSubNodes.size() == 0) {
                exitValue = 1;
                log.write(
                    "Non-Affymetrix experiment without processed data files\n");
                System.out.println(
                    "Non-Affymetrix experiment without processed data files");
                ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                "Non-Affymetrix experiment without processed data files");
                String[] errors = new String[1];
                errors[0] = "Non-Affymetrix experiment without processed data files";
                pex.setExceptionCausesAbort();
                pex.setProcessOutput(errors);
                throw pex;
              }
          }
        }
      }
    }
    catch (ParseException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
      String[] errors = new String[1];
      errors[0] = e.getMessage();
      pex.setProcessOutput(errors);
      throw pex;
    }
    catch (IOException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
      String[] errors = new String[1];
      errors[0] = e.getMessage();
      pex.setProcessOutput(errors);
      throw pex;
    }
    catch (RuntimeException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
      String[] errors = new String[1];
      errors[0] = e.getMessage();
      pex.setProcessOutput(errors);
      throw pex;
    }
    finally {
      try {
        if (exitValue == 0) {
          log.write("Experiment \"" +
                        accession.getAccession() +
                        "\" is eligible for Atlas\n");
        }
        else {
          log.write("Experiment \"" +
                        accession.getAccession() +
                        "\" is NOT eligible for Atlas\n");
        }
        log.write("Atlas Eligibility Check: FINISHED");
        log.write(
              "Eligibility checks for Gene Expression Atlas version 2.0.9.3: \n" +
              "1. Experiment has raw data for Affymetrix platforms or normalized data for all other platforms;\n" +
              "2. Array design(s) used in experiment are loaded into Atlas;\n" +
              "3. Type of experiment is from the list: \n" +
                  "transcription profiling by array,\n" +
                  "methylation profiling by array,\n" +
                  "tiling path by array,\n" +
                  "comparative genomic hybridization by array,\n" +
                  "microRNA profiling by array,\n" +
                  "RNAi profiling by array,\n" +
                  "ChIP-chip by array;\n" +
              "4. Experiments is not two-channel;\n" +
              "5. Experiment has factor values;\n" +
              "6. Factor types are from controlled vocabulary.");
        log.close();
      }
      catch (IOException e) {
        e.printStackTrace();
        ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
        String[] errors = new String[1];
        errors[0] = e.getMessage();
        pex.setProcessOutput(errors);
        throw pex;
      }
    }
    ProcessExecutionException pex =  new ProcessExecutionException(exitValue,"Something wrong in the code ");
    if (exitValue == 0) {
      return true;
    }
    else {
      String[] errors = new String[1];
      errors[0] = "Something wrong in the code ";
      pex.setProcessOutput(errors);
      throw pex;
    }
  }

  public boolean execute(Map<ConanParameter, String> parameters)
      throws ProcessExecutionException, IllegalArgumentException,
      InterruptedException {
    int exitValue = 0;
    AccessionParameter accession = new AccessionParameter();
    accession.setAccession(parameters.get(accessionParameter));
    String reportsDir =
        accession.getFile().getParentFile().getAbsolutePath() + File.separator +
            "reports";
    File reportsDirFile = new File(reportsDir);
    if (!reportsDirFile.exists()) {
      reportsDirFile.mkdirs();
    }
    String fileName = reportsDir + File.separator + accession.getAccession() +
        "_AtlasEligibilityCheck" +
        "_" + new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss").format(new Date()) +
        ".report";
    try {
      log = new BufferedWriter(new FileWriter(fileName));
      log.write("Atlas Eligibility Check: START\n");
    }
    catch (IOException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
      "Can't create report file '" + fileName + "'");
      String[] errors = new String[1];
      errors[0] =  "Can't create report file '" + fileName + "'";
      pex.setProcessOutput(errors);
      throw pex;
    }
    MAGETABParser parser = new MAGETABParser();
    try {
      MAGETABInvestigation investigation =
          parser.parse(accession.getFile().getAbsoluteFile());
      boolean isAtlasType = false;
      String restrictedExptType = "";
      if (investigation.IDF.getComments().containsKey("AEExperimentType")) {
        for (String exptType : investigation.IDF.getComments()
            .get("AEExperimentType")) {
          for (String AtlasType : controlledVocabularyDAO
              .getAtlasExperimentTypes()) {
            if (exptType.equals(AtlasType)) {
              isAtlasType = true;
            }
            else {
              restrictedExptType = exptType;
            }
          }
        }
      }
      else {
       for (String exptType : investigation.IDF.experimentalDesign) {
          for (String AtlasType : controlledVocabularyDAO
              .getAtlasExperimentTypes()) {
            if (exptType.equals(AtlasType)) {
              isAtlasType = true;
            }
          }
        }
       }
      if (!isAtlasType)
      {
        exitValue = 1;
        log.write(
            "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas\n");
        System.out.println(
            "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas");
        ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
        "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas");
        String[] errors = new String[1];
        errors[0] = "'Experiment Type' " + restrictedExptType + " is not accepted by Atlas";
        pex.setExceptionCausesAbort();
        pex.setProcessOutput(errors);
        throw pex;
      }
      else {
        if (investigation.SDRF.getNumberOfChannels() > 1) {
          exitValue = 1;
          log.write(
              "Two-channel experiment is not accepted by Atlas\n");
          System.out.println(
              "Two-channel experiment is not accepted by Atlas");
          ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
          "Two-channel experiment is not accepted by Atlas");
          String[] errors = new String[1];
          errors[0] = "Two-channel experiment is not accepted by Atlas";
          pex.setExceptionCausesAbort();
          pex.setProcessOutput(errors);
          throw pex;
        }
        Collection<HybridizationNode> hybridizationNodes =
            investigation.SDRF.getNodes(HybridizationNode.class);
        Collection<ArrayDataNode> rawDataNodes =
            investigation.SDRF.getNodes(ArrayDataNode.class);
        Collection<DerivedArrayDataNode> processedDataNodes =
            investigation.SDRF.getNodes(DerivedArrayDataNode.class);
        Collection<DerivedArrayDataMatrixNode> processedDataMatrixNodes =
            investigation.SDRF.getNodes(DerivedArrayDataMatrixNode.class);
        int factorValues = 0;
        for (HybridizationNode hybNode : hybridizationNodes)
        {
          if (hybNode.factorValues.size() > 0) {
            factorValues++;
          }
          ArrayDesignAccessions.clear();
          for (ArrayDesignAttribute arrayDesign : hybNode.arrayDesigns) {
            if (!ArrayDesignAccessions
                .contains(arrayDesign.getAttributeValue())) {
              ArrayDesignAccessions.add(arrayDesign.getAttributeValue());
            }
          }
        }
        if (factorValues == 0) {
          exitValue = 1;
          log.write(
              "Experiment does not have Factor Values\n");
          System.out.println(
              "Experiment does not have Factor Values");
          ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
          "Experiment does not have Factor Values");
          String[] errors = new String[1];
          errors[0] = "Experiment does not have Factor Values";
          pex.setExceptionCausesAbort();
          pex.setProcessOutput(errors);
          throw pex;
        }
        boolean factorTypesFromCV = true;
        List<String> missedFactorType = new ArrayList<String>();
        for (String factorType : investigation.IDF.experimentalFactorType) {
          if (!controlledVocabularyDAO
              .getAtlasFactorTypes().contains(factorType)) {
            factorTypesFromCV = false;
            missedFactorType.add(factorType);
          }
        }
        if (!factorTypesFromCV) {
          exitValue = 1;
          log.write(
              "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType + "\n");
          System.out.println(
              "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType);
          ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
          "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType);
          String[] errors = new String[1];
          errors[0] = "Experiment have Factor Types that are not in controlled vocabulary:" +
                  missedFactorType;
          pex.setExceptionCausesAbort();
          pex.setProcessOutput(errors);
          throw pex;
        }
        for (String arrayDesign : ArrayDesignAccessions) {
          ArrayDesignExistenceChecking arrayDesignExistenceChecking =
              new ArrayDesignExistenceChecking();
          String arrayCheckResult =
              arrayDesignExistenceChecking.execute(arrayDesign);
          if (arrayCheckResult.equals("empty") ||
              arrayCheckResult.equals("no")) {
            exitValue = 1;
            log.write("Array design '" +
                          arrayDesign +
                          "' used in experiment is not in Atlas\n");
            System.out.println("Array design '" +
                                   arrayDesign +
                                   "' used in experiment is not in Atlas");
            ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
            "Array design '" +
                                   arrayDesign +
                                   "' used in experiment is not in Atlas");
            String[] errors = new String[1];
            errors[0] = "Array design '" +
                                   arrayDesign +
                                   "' used in experiment is not in Atlas";
            pex.setExceptionCausesAbort();
            pex.setProcessOutput(errors);
            throw pex;
          }
          else {
            Collection<HybridizationNode> hybridizationSubNodes =
                new ArrayList<HybridizationNode>();
            Collection<Node> rawDataSubNodes = new ArrayList<Node>();
            Collection<Node> processedDataSubNodes = new ArrayList<Node>();
            Collection<Node> processedDataMatrixSubNodes =
                new ArrayList<Node>();
            if (ArrayDesignAccessions.size() > 1) {
              for (HybridizationNode hybNode : hybridizationNodes) {
                ArrayDesignAttribute attribute = new ArrayDesignAttribute();
                attribute.setAttributeValue(arrayDesign);
                if (hybNode.arrayDesigns.contains(attribute)) {
                  hybridizationSubNodes.add(hybNode);
                  getNodes(hybNode, ArrayDataNode.class, rawDataSubNodes);
                  getNodes(hybNode, DerivedArrayDataNode.class,
                           processedDataSubNodes);
                  getNodes(hybNode, DerivedArrayDataMatrixNode.class,
                           processedDataMatrixSubNodes);
                }
              }
            }
            else {
              hybridizationSubNodes = hybridizationNodes;
              for (ArrayDataNode node : rawDataNodes) {
                rawDataSubNodes.add(node);
              }
              for (DerivedArrayDataNode node : processedDataNodes) {
                processedDataSubNodes.add(node);
              }
              for (DerivedArrayDataMatrixNode node : processedDataMatrixNodes) {
                processedDataMatrixSubNodes.add(node);
              }
            }
            if (arrayCheckResult.equals("affy") &&
                hybridizationSubNodes.size() != rawDataSubNodes.size())
            {
              exitValue = 1;
              log.write(
                  "Affymetrix experiment without raw data files\n");
              System.out.println(
                  "Affymetrix experiment without raw data files");
              ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
              "Affymetrix experiment without raw data files");
              String[] errors = new String[1];
              errors[0] = "Affymetrix experiment without raw data files";
              pex.setExceptionCausesAbort();
              pex.setProcessOutput(errors);
              throw pex;
            }
            else
              if (!arrayCheckResult.equals("affy") && processedDataSubNodes.size() == 0 &&
                  processedDataMatrixSubNodes.size() == 0) {
                exitValue = 1;
                log.write(
                    "Non-Affymetrix experiment without processed data files\n");
                System.out.println(
                    "Non-Affymetrix experiment without processed data files");
                ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                "Non-Affymetrix experiment without processed data files");
                String[] errors = new String[1];
                errors[0] = "Non-Affymetrix experiment without processed data files";
                pex.setExceptionCausesAbort();
                pex.setProcessOutput(errors);
                throw pex;
              }
          }
        }
      }
    }
    catch (ParseException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
      String[] errors = new String[1];
      errors[0] = e.getMessage();
      pex.setProcessOutput(errors);
      throw pex;
    }
    catch (IOException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
      String[] errors = new String[1];
      errors[0] = e.getMessage();
      pex.setProcessOutput(errors);
      throw pex;
    }
    catch (RuntimeException e) {
      exitValue = 1;
      e.printStackTrace();
      ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
      String[] errors = new String[1];
      errors[0] = e.getMessage();
      pex.setProcessOutput(errors);
      throw pex;
    }
    finally {
      try {
        if (exitValue == 0) {
          log.write("Experiment \"" +
                        accession.getAccession() +
                        "\" is eligible for Atlas\n");
        }
        else {
          log.write("Experiment \"" +
                        accession.getAccession() +
                        "\" is NOT eligible for Atlas\n");
        }
        log.write("Atlas Eligibility Check: FINISHED\n");
        log.write(
              "Eligibility checks for Gene Expression Atlas version 2.0.9.3: \n" +
              "1. Experiment has raw data for Affymetrix platforms or normalized data for all other platforms;\n" +
              "2. Array design(s) used in experiment are loaded into Atlas;\n" +
              "3. Type of experiment is from the list: \n" +
                  "transcription profiling by array,\n" +
                  "methylation profiling by array,\n" +
                  "tiling path by array,\n" +
                  "comparative genomic hybridization by array,\n" +
                  "microRNA profiling by array,\n" +
                  "RNAi profiling by array,\n" +
                  "ChIP-chip by array;\n" +
              "4. Experiments is not two-channel;\n" +
              "5. Experiment has factor values;\n" +
              "6. Factor types are from controlled vocabulary.");
        log.close();
      }
      catch (IOException e) {
        e.printStackTrace();
        ProcessExecutionException pex =  new ProcessExecutionException(exitValue,
                e.getMessage());
        String[] errors = new String[1];
        errors[0] = e.getMessage();
        pex.setProcessOutput(errors);
        throw pex;
      }
    }
    ProcessExecutionException pex =  new ProcessExecutionException(exitValue,"Something wrong in the code ");
    if (exitValue == 0) {
      return true;
    }
    else {
      String[] errors = new String[1];
      errors[0] = "Something wrong in the code ";
      pex.setProcessOutput(errors);
      throw pex;
    }
  }
