Esempio n. 1
0
 /**
  * Process the identifiers.
  *
  * @param type The type of thing these identifiers are.
  * @param input The creation input.
  * @param ids The identifiers.
  * @param unmatchedIds A collector for unmatched identifiers.
  * @param tempBag The temporary bag to add results to.
  * @throws IOException If we can't from the request.
  * @throws ClassNotFoundException if the type is not valid.
  * @throws InterMineException If something goes wrong building the bag.
  * @throws ObjectStoreException If there is a problem on the database level.
  */
 protected void processIdentifiers(
     final String type,
     ListCreationInput input,
     final Set<String> ids,
     final Set<String> unmatchedIds,
     final InterMineBag tempBag)
     throws IOException, ClassNotFoundException, InterMineException, ObjectStoreException {
   final Collection<String> addIssues = input.getAddIssues();
   String line;
   final StrMatcher matcher = getMatcher();
   final BufferedReader r = getReader(request);
   try {
     while ((line = r.readLine()) != null) {
       final StrTokenizer st = new StrTokenizer(line, matcher, StrMatcher.doubleQuoteMatcher());
       while (st.hasNext()) {
         final String token = st.nextToken();
         ids.add(token);
       }
       if (ids.size() >= BAG_QUERY_MAX_BATCH_SIZE) {
         addIdsToList(ids, tempBag, type, input.getExtraValue(), unmatchedIds, addIssues);
         ids.clear();
       }
     }
   } finally {
     if (r != null) {
       r.close();
     }
   }
   if (ids.size() > 0) {
     addIdsToList(ids, tempBag, type, input.getExtraValue(), unmatchedIds, addIssues);
   }
 }
Esempio n. 2
0
  /**
   * Parses the pattern string, which should be a comma separated list of regular expressions, each
   * of which may be surrounded with double quotes.
   *
   * @param inStr pattern string to parse
   * @return list of pattern regular expressions
   */
  private ArrayList<Pattern> parsePatternString(String inStr) {
    ArrayList<Pattern> result = new ArrayList<Pattern>();

    StrTokenizer tokenizer = new StrTokenizer(inStr, ',', '"');
    tokenizer.setIgnoreEmptyTokens(true);
    tokenizer.setIgnoredMatcher(StrMatcher.charSetMatcher(" \t\n\r"));

    while (tokenizer.hasNext()) {
      String tok = (String) tokenizer.next();
      Pattern pat = Pattern.compile(tok);
      result.add(pat);
    }

    return result;
  }
Esempio n. 3
0
 /**
  * Converts a String back to connection parameters.
  *
  * @param input String from configuration
  * @return JDBC connection parameters
  */
 protected static Properties propertiesFromString(String input) {
   if (input != null && !input.isEmpty()) {
     Properties result = new Properties();
     StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
     StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
     valueTokenizer.setDelimiterChar('=');
     while (propertyTokenizer.hasNext()) {
       valueTokenizer.reset(propertyTokenizer.nextToken());
       String[] values = valueTokenizer.getTokenArray();
       if (values.length == 2) {
         result.put(values[0], values[1]);
       }
     }
     return result;
   } else {
     return null;
   }
 }
  protected static <T> void parseEDISegmentFields(
      EDIMessage ediMessage, Object segment, String segmentLine)
      throws IllegalAccessException, InvocationTargetException, ClassNotFoundException,
          ConversionException, InstantiationException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Before Field Values: " + ReflectionToStringBuilder.toString(segment));
      LOG.debug("Segment Values: " + segmentLine);
    }

    // now, tokenize the line, and set the fields.
    StrTokenizer tokenizer = new StrTokenizer(segmentLine, ediMessage.elementDelimiter());

    tokenizer.setEmptyTokenAsNull(true);
    tokenizer.setIgnoreEmptyTokens(false);

    // move past the initial tag.
    tokenizer.next();

    Iterator<Field> fieldIterator =
        Arrays.asList(segment.getClass().getDeclaredFields()).iterator();
    while (tokenizer.hasNext() && fieldIterator.hasNext()) {
      Field field = fieldIterator.next();
      String val = tokenizer.nextToken();

      // check field to see if it is a component of regular field type.
      if (field.isAnnotationPresent(EDIComponent.class)) {
        EDIComponent ediComponent = field.getAnnotation(EDIComponent.class);
        Collection obj = CollectionFactory.newInstance(field.getType());
        Class objType = getCollectionType(field);

        char componentDelimiter =
            ediComponent.delimiter() == Character.UNASSIGNED
                ? ediMessage.componentDelimiter()
                : ediComponent.delimiter();

        // parse each element to the collection.
        StrTokenizer componentTokenizer = new StrTokenizer(val, componentDelimiter);
        componentTokenizer.setEmptyTokenAsNull(true);
        componentTokenizer.setIgnoreEmptyTokens(false);

        while (componentTokenizer.hasNext()) {
          String component = componentTokenizer.nextToken();
          Object fieldObj =
              objType.cast(FieldAwareConverter.convertFromString(objType, field, component));
          obj.add(fieldObj);
        }
        BeanUtils.setProperty(segment, field.getName(), obj);
      } else {
        if (val == null) {
          LOG.debug("  " + field.getName() + " -> null");
          continue;
        }

        // try and populate the field.

        try {
          Object fieldObj = FieldAwareConverter.convertFromString(field.getType(), field, val);
          LOG.debug("  " + field.getName() + " -> " + val);

          BeanUtils.setProperty(segment, field.getName(), fieldObj);
        } catch (Exception e) {
          throw new ConversionException(
              "Exception setting: "
                  + segment.getClass()
                  + "."
                  + field.getName()
                  + " with value: "
                  + val,
              e);
        }
      }
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("After Field Values: " + ReflectionToStringBuilder.toString(segment));
    }
  }