Пример #1
0
  private void addNames(Accessions accession, List<NameLinkType> nameList)
      throws IllegalAccessException, InvocationTargetException, DuplicateLinkException,
          UnknownLookupListException, PersistenceException, NoSuchAlgorithmException,
          UnsupportedEncodingException {
    NamesDAO namesDao = new NamesDAO();
    ArchDescriptionNames accessionName;

    for (NameLinkType thisNameLink : nameList) {
      accessionName =
          new ArchDescriptionNames(lookupName(namesDao, thisNameLink.getName()), accession);
      ImportUtils.nullSafeSet(
          accessionName,
          ArchDescriptionNames.PROPERTYNAME_NAME_LINK_FUNCTION,
          thisNameLink.getNameLinkFunction());
      ImportUtils.nullSafeSet(
          accessionName, ArchDescriptionNames.PROPERTYNAME_FORM, thisNameLink.getNameLinkForm());
      ImportUtils.nullSafeSet(
          accessionName, ArchDescriptionNames.PROPERTYNAME_ROLE, thisNameLink.getNameLinkRole());
      accession.addName(accessionName);
    }
  }
Пример #2
0
  /**
   * Import the file.
   *
   * @param importFile the file to import.
   * @param controller the controller to use.
   * @param progressPanel - the progress panel to display heartbeat messages
   * @return if we succeded
   */
  public boolean importFile(
      File importFile, DomainImportController controller, InfiniteProgressPanel progressPanel)
      throws ImportException {

    Collection<DomainObject> collection = new ArrayList<DomainObject>();

    if (importFile != null) {
      JAXBContext context;
      try {
        LookupListUtils.initIngestReport();
        context = JAXBContext.newInstance("org.archiviststoolkit.structure.accessionImport");
        AccessionRecords accessionRecords =
            (AccessionRecords) context.createUnmarshaller().unmarshal(importFile);
        Accessions accession;
        int recordCount = 1;
        progressPanel.setTextLine("Importing...", 1);
        PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(RecordType.class);
        for (RecordType record : accessionRecords.getRecord()) {
          // check to see if the process was cancelled  at this point if so just return
          if (progressPanel.isProcessCancelled()) {
            return false;
          }

          progressPanel.setTextLine("Processing record " + recordCount, 2);
          accession = new Accessions();
          accession.setRepository(repository);

          for (PropertyDescriptor descriptor : descriptors) {
            Class propertyType = descriptor.getPropertyType();
            if (propertyType == XMLGregorianCalendar.class) {
              ImportUtils.nullSafeDateSet(
                  accession,
                  descriptor.getName(),
                  (XMLGregorianCalendar) descriptor.getReadMethod().invoke(record));
            } else if (propertyType == String.class
                || propertyType == BigInteger.class
                || propertyType == BigDecimal.class) {
              ImportUtils.nullSafeSet(
                  accession, descriptor.getName(), descriptor.getReadMethod().invoke(record));

            } else if (propertyType == Boolean.class) {
              // this hack is needed because jaxb has a bug and the read method starts
              // with "is" instead of "get"
              String writeMethodName = descriptor.getWriteMethod().getName();
              String readMethodName = writeMethodName.replaceFirst("set", "is");
              Method readMethod = RecordType.class.getMethod(readMethodName);
              ImportUtils.nullSafeSet(accession, descriptor.getName(), readMethod.invoke(record));
            }
          }
          parseAccessionNumber(accession, record.getAccessionNumber());
          addSubjects(accession, record.getSubjectLink());
          addNames(accession, record.getNameLink());
          addResource(
              accession,
              record.getResourceIdentifier(),
              controller,
              accession.getAccessionNumber(),
              recordCount);
          collection.add(accession);
          recordCount++;
        }
        controller.domainImport(collection, ApplicationFrame.getInstance(), progressPanel);
        ImportExportLogDialog dialog =
            new ImportExportLogDialog(
                controller.constructFinalImportLogText()
                    + "\n\n"
                    + LookupListUtils.getIngestReport(),
                ImportExportLogDialog.DIALOG_TYPE_IMPORT);
        progressPanel.close();
        dialog.showDialog();
      } catch (JAXBException e) {
        progressPanel.close();
        new ErrorDialog(
                ApplicationFrame.getInstance(), "There is a problem importing accessions.", e)
            .showDialog();
      } catch (IllegalAccessException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (InvocationTargetException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (UnknownLookupListException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (ValidationException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (PersistenceException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (DuplicateLinkException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (NoSuchMethodException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (NoSuchAlgorithmException e) {
        new ErrorDialog("", e).showDialog();
      } catch (UnsupportedEncodingException e) {
        new ErrorDialog("", e).showDialog();
      }
    }
    return (true);
  }
Пример #3
0
  private Names lookupName(NamesDAO namesDao, NameComplexType nameFromImport)
      throws IllegalAccessException, InvocationTargetException, UnknownLookupListException,
          PersistenceException, NoSuchAlgorithmException, UnsupportedEncodingException {
    Names name = new Names();
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_NAME_TYPE, nameFromImport.getNameType());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_SORT_NAME, nameFromImport.getSortName());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_NAME_RULE, nameFromImport.getNameRule());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_NUMBER, nameFromImport.getNumber());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_QUALIFIER, nameFromImport.getQualifier());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_DESCRIPTION_TYPE, nameFromImport.getDescriptionType());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_DESCRIPTION_NOTE, nameFromImport.getDescriptionNote());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CITATION, nameFromImport.getCitation());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_SALUTATION, nameFromImport.getSalutation());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_ADDRESS_1, nameFromImport.getContactAddress1());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_ADDRESS_2, nameFromImport.getContactAddress2());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CONTACT_CITY, nameFromImport.getContactCity());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_REGION, nameFromImport.getContactRegion());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_COUNTRY, nameFromImport.getContactCountry());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_MAIL_CODE, nameFromImport.getContactMailCode());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_PHONE, nameFromImport.getContactPhone());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CONTACT_FAX, nameFromImport.getContactFax());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CONTACT_EMAIL, nameFromImport.getContactEmail());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_CONTACT_NAME, nameFromImport.getContactName());
    ImportUtils.nullSafeSet(name, Names.PROPERTYNAME_FAMILY_NAME, nameFromImport.getFamilyName());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_FAMILY_NAME_PREFIX, nameFromImport.getFamilyNamePrefix());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_CORPORATE_PRIMARY_NAME, nameFromImport.getCorporatePrimaryName());
    ImportUtils.nullSafeSet(
        name,
        Names.PROPERTYNAME_CORPORATE_SUBORDINATE_1,
        nameFromImport.getCorporateSubordinate1());
    ImportUtils.nullSafeSet(
        name,
        Names.PROPERTYNAME_CORPORATE_SUBORDINATE_2,
        nameFromImport.getCorporateSubordinate2());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_PRIMARY_NAME, nameFromImport.getPersonalPrimaryName());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_REST_OF_NAME, nameFromImport.getPersonalRestOfName());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_PREFIX, nameFromImport.getPersonalPrefix());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_SUFFIX, nameFromImport.getPersonalSuffix());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_FULLER_FORM, nameFromImport.getPersonalFullerForm());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_TITLE, nameFromImport.getPersonalTitle());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_DATES, nameFromImport.getPersonalDates());
    ImportUtils.nullSafeSet(
        name, Names.PROPERTYNAME_PERSONAL_DIRECT_ORDER, nameFromImport.isPersonalDirectOrder());
    if (nameFromImport.getNameSource() == null) {
      name.setNameSource("ingest");
    } else {
      name.setNameSource(nameFromImport.getNameSource());
    }
    if (name.getSortName() == null || name.getSortName().length() == 0) {
      name.createSortName();

      // check to see if sort name is still empty. If so, set it to " " so that
      // this record can be inserted into an Oracle DB without throwing an error
      if (name.getSortName().length() == 0) {
        name.setSortName(" ");
      }
    }
    NameUtils.setMd5Hash(name);

    return namesDao.lookupName(name, true);
  }