コード例 #1
0
  /**
   * Imports OntologyTerm from tab/comma delimited File.
   *
   * @param OntologyTermFile a tab delimited file with OntologyTerm data.
   */
  private static void importOntologyTerm(Database db, File OntologyTermFile)
      throws DatabaseException, IOException, Exception {
    logger.debug("trying to import " + OntologyTermFile);
    if (!OntologyTermFile.exists()) {
      logger.warn("OntologyTerm.txt file is missing, skipped import");
    } else {
      // read OntologyTerm from file
      CsvReader reader = new CsvFileReader(OntologyTermFile);
      List<OntologyTerm> ontologyTermList =
          db.toList(OntologyTerm.class, reader, Integer.MAX_VALUE); // should have no limit
      logger.debug("loaded " + ontologyTermList.size() + " OntologyTerm objects");

      // redirect incoming and outgoing fkeys
      List<Integer> ontologyTermIds = new ArrayList<Integer>(); // also doesn't scale
      for (int i = 0;
          i < ontologyTermList.size();
          i++) // sorry, not a real list so need to put back!!
      {
        OntologyTerm object = ontologyTermList.get(i);

        // remember index of this id for incoming fkeys
        ontologyTermIds.add(object.getId());

        // redirect outgoing fkeys
        if (object.getOntology() != null)
          object.setOntology_Id(ontologyIdMap.get(object.getOntology_Id()));

        // add assay back to list
        ontologyTermList.set(i, object);
      }
      // add to database
      db.add(ontologyTermList);
      for (int i = 0; i < ontologyTermList.size(); i++) {
        ontologyTermIdMap.put(ontologyTermIds.get(i), ontologyTermList.get(i).getId());
      }
    }
  }
  @Override
  public List<HtmlInput<?>> getInputs() {
    List<HtmlInput<?>> inputs = new ArrayList<HtmlInput<?>>();
    // Autoid: Field(entity=ProtocolApplication_ontol11768, name=autoid, type=int, auto=true,
    // nillable=false, readonly=false, default=null)
    {
      IntInput input =
          new IntInput("ProtocolApplication_ontol11768_autoid", getEntity().getAutoid());

      input.setLabel("autoid");
      input.setDescription("automatic id field to ensure ordering of mrefs");
      input.setNillable(false);
      input.setReadonly(isReadonly() || getEntity().isReadonly());
      input.setHidden(!isNewRecord());
      if (this.getCompactView().size() > 0 && !this.getCompactView().contains(input.getName())) {
        input.setCollapse(true);
      }

      inputs.add(input);
    }
    // OntologyReference: Field(entity=ProtocolApplication_ontol11768, name=ontologyReference,
    // type=xref[OntologyTerm.id], xref_label='name', auto=false, nillable=false, readonly=false,
    // default=null)
    {
      // TODO: when we have JPA this should become:
      // XrefInput input = new XrefInput("ProtocolApplication_ontol11768_ontologyReference",
      // getEntity().getOntologyReference());
      // create xref dummy object
      OntologyTerm dummy = null;
      if (getEntity().getOntologyReference_Id() != null) {
        dummy = new OntologyTerm();
        dummy.setId(getEntity().getOntologyReference_Id());
        dummy.setName(getEntity().getOntologyReference_Name());
      }
      XrefInput input =
          new XrefInput(
              "ProtocolApplication_ontol11768_ontologyReference",
              org.molgenis.core.OntologyTerm.class,
              dummy);

      input.setLabel("ontologyReference");
      input.setDescription("");
      input.setNillable(false);
      input.setReadonly(isReadonly() || getEntity().isReadonly());
      if (this.getHiddenColumns().contains(input.getName())) {
        input.setHidden(!isNewRecord());
      }
      if (this.getCompactView().size() > 0 && !this.getCompactView().contains(input.getName())) {
        input.setCollapse(true);
      }

      inputs.add(input);
    }
    // InvestigationElement: Field(entity=ProtocolApplication_ontol11768, name=InvestigationElement,
    // type=xref[ProtocolApplication.id], xref_label=, auto=false, nillable=false, readonly=false,
    // default=null)
    {
      // TODO: when we have JPA this should become:
      // XrefInput input = new XrefInput("ProtocolApplication_ontol11768_InvestigationElement",
      // getEntity().getInvestigationElement());
      // create xref dummy object
      ProtocolApplication dummy = null;
      if (getEntity().getInvestigationElement_Id() != null) {
        dummy = new ProtocolApplication();
        dummy.setId(getEntity().getInvestigationElement_Id());
        dummy.setName(getEntity().getInvestigationElement_Name());
      }
      XrefInput input =
          new XrefInput(
              "ProtocolApplication_ontol11768_InvestigationElement",
              org.molgenis.protocol.ProtocolApplication.class,
              dummy);

      input.setLabel("InvestigationElement");
      input.setDescription("");
      input.setNillable(false);
      input.setReadonly(isReadonly() || getEntity().isReadonly());
      if (this.getHiddenColumns().contains(input.getName())) {
        input.setHidden(!isNewRecord());
      }
      if (this.getCompactView().size() > 0 && !this.getCompactView().contains(input.getName())) {
        input.setCollapse(true);
      }

      inputs.add(input);
    }

    return inputs;
  }
  public ImportWizardExcelPrognosis(File excelFile) throws Exception {

    Workbook workbook = Workbook.getWorkbook(excelFile);
    ArrayList<String> lowercasedSheetNames = new ArrayList<String>();
    Map<String, String> lowerToOriginalName = new HashMap<String, String>();

    try {

      for (String sheetName : workbook.getSheetNames()) {
        lowercasedSheetNames.add(sheetName.toLowerCase());
        lowerToOriginalName.put(sheetName.toLowerCase(), sheetName);
      }

      if (lowercasedSheetNames.contains("molgenisrole")) {
        String originalSheetname = lowerToOriginalName.get("molgenisrole");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisRoleExcelReader excelReader = new MolgenisRoleExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisRole entity = new MolgenisRole();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("molgenisgroup")) {
        String originalSheetname = lowerToOriginalName.get("molgenisgroup");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisGroupExcelReader excelReader = new MolgenisGroupExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisGroup entity = new MolgenisGroup();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("institute")) {
        String originalSheetname = lowerToOriginalName.get("institute");
        Sheet sheet = workbook.getSheet(originalSheetname);
        InstituteExcelReader excelReader = new InstituteExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        Institute entity = new Institute();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("ontology")) {
        String originalSheetname = lowerToOriginalName.get("ontology");
        Sheet sheet = workbook.getSheet(originalSheetname);
        OntologyExcelReader excelReader = new OntologyExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        Ontology entity = new Ontology();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("ontologyterm")) {
        String originalSheetname = lowerToOriginalName.get("ontologyterm");
        Sheet sheet = workbook.getSheet(originalSheetname);
        OntologyTermExcelReader excelReader = new OntologyTermExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        OntologyTerm entity = new OntologyTerm();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("person")) {
        String originalSheetname = lowerToOriginalName.get("person");
        Sheet sheet = workbook.getSheet(originalSheetname);
        PersonExcelReader excelReader = new PersonExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        Person entity = new Person();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("molgenisuser")) {
        String originalSheetname = lowerToOriginalName.get("molgenisuser");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisUserExcelReader excelReader = new MolgenisUserExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisUser entity = new MolgenisUser();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("molgenisrolegrouplink")) {
        String originalSheetname = lowerToOriginalName.get("molgenisrolegrouplink");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisRoleGroupLinkExcelReader excelReader = new MolgenisRoleGroupLinkExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisRoleGroupLink entity = new MolgenisRoleGroupLink();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("molgenisfile")) {
        String originalSheetname = lowerToOriginalName.get("molgenisfile");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisFileExcelReader excelReader = new MolgenisFileExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisFile entity = new MolgenisFile();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("runtimeproperty")) {
        String originalSheetname = lowerToOriginalName.get("runtimeproperty");
        Sheet sheet = workbook.getSheet(originalSheetname);
        RuntimePropertyExcelReader excelReader = new RuntimePropertyExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        RuntimeProperty entity = new RuntimeProperty();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("publication")) {
        String originalSheetname = lowerToOriginalName.get("publication");
        Sheet sheet = workbook.getSheet(originalSheetname);
        PublicationExcelReader excelReader = new PublicationExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        Publication entity = new Publication();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("usecase")) {
        String originalSheetname = lowerToOriginalName.get("usecase");
        Sheet sheet = workbook.getSheet(originalSheetname);
        UseCaseExcelReader excelReader = new UseCaseExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        UseCase entity = new UseCase();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("molgenisentity")) {
        String originalSheetname = lowerToOriginalName.get("molgenisentity");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisEntityExcelReader excelReader = new MolgenisEntityExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisEntity entity = new MolgenisEntity();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }
      if (lowercasedSheetNames.contains("molgenispermission")) {
        String originalSheetname = lowerToOriginalName.get("molgenispermission");
        Sheet sheet = workbook.getSheet(originalSheetname);
        MolgenisPermissionExcelReader excelReader = new MolgenisPermissionExcelReader();
        List<String> allHeaders = excelReader.getNonEmptyHeaders(sheet);
        MolgenisPermission entity = new MolgenisPermission();
        headersToMaps(originalSheetname, allHeaders, entity.getFields());
      }

      for (String sheetName : lowerToOriginalName.values()) {
        if (importOrder.contains(sheetName)) {
          sheetsImportable.put(sheetName, true);
        } else {
          sheetsImportable.put(sheetName, false);
        }
      }

    } catch (Exception e) {
      throw e;
    } finally {
      workbook.close();
    }
  }