Esempio n. 1
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));
      }
    }
  }
Esempio n. 2
0
 private String cleanAndTrim(String valueToClean, Class clazz, String propertyName) {
   String returnString = StringHelper.cleanUpWhiteSpace(valueToClean);
   ATFieldInfo fieldInfo = ATFieldInfo.getFieldInfo(clazz, propertyName);
   if (fieldInfo.getStringLengthLimit() != null && fieldInfo.getStringLengthLimit() > 0) {
     return StringHelper.trimToLength(returnString, fieldInfo.getStringLengthLimit());
   } else {
     return returnString;
   }
 }
Esempio n. 3
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");
      }
    }
  }