コード例 #1
0
  private void addSubjects(Accessions accession, List<SubjectLinkType> subjectList)
      throws PersistenceException, ValidationException, UnknownLookupListException {
    SubjectsDAO subjectDao = new SubjectsDAO();
    Subjects subject;
    ArchDescriptionSubjects accessionSubject;
    String type;
    String source;

    for (SubjectLinkType thisSubject : subjectList) {
      type =
          cleanAndTrim(
              thisSubject.getSubjectTermType(),
              Subjects.class,
              Subjects.PROPERTYNAME_SUBJECT_TERM_TYPE);
      if (type == null) {
        type = "ingest";
      }
      source =
          cleanAndTrim(
              thisSubject.getSubjectSource(), Subjects.class, Subjects.PROPERTYNAME_SUBJECT_SOURCE);
      if (source == null) {
        source = "ingest";
      }
      subject =
          subjectDao.lookupSubject(
              cleanAndTrim(
                  thisSubject.getSubjectTerm(), Subjects.class, Subjects.PROPERTYNAME_SUBJECT_TERM),
              type,
              source,
              true);
      accessionSubject = new ArchDescriptionSubjects(subject, accession);
      accession.addSubject(accessionSubject);
    }
  }
コード例 #2
0
  private void parseAccessionNumber(Accessions accession, IdentifierType value) {
    String composite = value.getComposite();

    if (composite != null) {
      StringTokenizer st = new StringTokenizer(composite, "./-");
      int count = 0;
      String thisToken;
      while (st.hasMoreTokens()) {
        count++;
        thisToken = StringHelper.cleanUpWhiteSpace((String) st.nextElement());
        if (count == 1) {
          accession.setAccessionNumber1(
              StringHelper.trimToLength(
                  thisToken,
                  ATFieldInfo.checkFieldLength(
                      Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_1)));
        } else if (count == 2) {
          accession.setAccessionNumber2(
              StringHelper.trimToLength(
                  thisToken,
                  ATFieldInfo.checkFieldLength(
                      Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_2)));
        } else if (count == 3) {
          accession.setAccessionNumber3(
              StringHelper.trimToLength(
                  thisToken,
                  ATFieldInfo.checkFieldLength(
                      Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_3)));
        } else if (count == 4) {
          accession.setAccessionNumber4(
              StringHelper.trimToLength(
                  thisToken,
                  ATFieldInfo.checkFieldLength(
                      Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_4)));
        }
      }
    } else {
      accession.setAccessionNumber1(
          cleanAndTrim(
              value.getPart1(), Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_1));
      if (value.getPart2() != null) {
        accession.setAccessionNumber2(
            cleanAndTrim(
                value.getPart2(), Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_2));
      }
      if (value.getPart3() != null) {
        accession.setAccessionNumber3(
            cleanAndTrim(
                value.getPart3(), Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_3));
      }
      if (value.getPart4() != null) {
        accession.setAccessionNumber4(
            cleanAndTrim(
                value.getPart4(), Accessions.class, Accessions.PROPERTYNAME_ACCESSION_NUMBER_4));
      }
    }
  }
コード例 #3
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);
    }
  }
コード例 #4
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);
  }
コード例 #5
0
  private void addResource(
      Accessions accession,
      IdentifierType resourceId,
      DomainImportController controller,
      String accesionNumber,
      int recordNumber)
      throws ImportException {

    if (resourceId != null) {

      String resourceId1;
      String resourceId2 = null;
      String resourceId3 = null;
      String resourceId4 = null;
      if (resourceId.getComposite() != null) {
        resourceId1 =
            StringHelper.trimToLength(
                resourceId.getComposite(),
                ATFieldInfo.checkFieldLength(
                    Resources.class, Resources.PROPERTYNAME_RESOURCE_IDENTIFIER_1));
      } else {
        resourceId1 = resourceId.getPart1();
        resourceId2 = resourceId.getPart2();
        resourceId3 = resourceId.getPart3();
        resourceId4 = resourceId.getPart4();
      }

      ResourcesDAO resourceDao = new ResourcesDAO();
      Resources resource;
      if (resourceCreation.equalsIgnoreCase(AccessionImportXmlHandler.RESOURCE_CREATION_NONE)) {
        resource =
            resourceDao.lookupResource(
                resourceId1, resourceId2, resourceId3, resourceId4, false, repository);
      } else {
        resource =
            resourceDao.lookupResource(
                resourceId1, resourceId2, resourceId3, resourceId4, true, repository);
      }
      if (resourceDao.getNewRecordCreated()
          && resourceCreation.equalsIgnoreCase(AccessionImportXmlHandler.RESOURCE_CREATION_FULL)) {
        try {
          resource = (Resources) resourceDao.findByPrimaryKeyLongSession(resource.getIdentifier());
          resource.populateResourceFromAccession(accession);
          resourceDao.updateLongSession(resource);

        } catch (LookupException e) {
          throw new ImportException(
              "Error creating resource: " + resourceId + ", " + e.getMessage(), e);
        } catch (PersistenceException e) {
          throw new ImportException(
              "Error creating resource: " + resourceId + ", " + e.getMessage(), e);
        } catch (DuplicateLinkException e) {
          throw new ImportException(
              "Error creating resource: duplicate link" + resourceId + ", " + e.getMessage(), e);
        }
      }
      if (resource != null) {
        AccessionsResources accessionResource = new AccessionsResources(resource, accession);
        accession.addAccessionsResources(accessionResource);
      }
    } else {
      if (!resourceCreation.equalsIgnoreCase(AccessionImportXmlHandler.RESOURCE_CREATION_NONE)) {
        controller.addLineToImportLog(
            "Record # "
                + recordNumber
                + " - "
                + accesionNumber
                + " has no resource id so no resource record was created");
      }
    }
  }