Пример #1
0
  public String getFullNamePattern() {
    List<String> nameParts = new ArrayList<String>();
    if (!StringUtils.isEmpty(_lastNamePattern)) {
      nameParts.add(_lastNamePattern + "*");
    } else if (!StringUtils.isEmpty(_firstNamePattern)) {
      nameParts.add("*");
    }

    if (!StringUtils.isEmpty(_firstNamePattern)) {
      nameParts.add(_firstNamePattern + "*");
    }
    return Joiner.on(", ").join(nameParts);
  }
Пример #2
0
 @SuppressWarnings("unchecked")
 @UICommand
 public String findScreenerByNamePattern() {
   String pattern = getFullNamePattern();
   if (!StringUtils.isEmpty(pattern)) {
     _screenerSearchResults.searchAll(
         "Screeners matching "
             + pattern); // potentially poor performance, but "correct", as it always searches
                         // latest additions and changes to users
     TableColumn<ScreeningRoomUser, String> column =
         (TableColumn<ScreeningRoomUser, String>)
             _screenerSearchResults.getColumnManager().getColumn("Name");
     // Note: the assumption is that alphabetic sort when searching on name is desired
     _screenerSearchResults.getColumnManager().setSortColumn(column);
     _screenerSearchResults.getColumnManager().setSortDirection(SortDirection.ASCENDING);
     column.resetCriteria().setOperatorAndValue(Operator.TEXT_LIKE, pattern);
     if (_screenerSearchResults.getRowCount() == 0) {
       showMessage("users.noUserWithMatchingName", pattern);
       resetSearchFields(); // if we don't reset now, and the user decides to not search again, the
                            // search criteria remain in the input fields
     } else if (_screenerSearchResults.getRowCount() == 1) {
       _screenerSearchResults.getRowsPerPageSelector().setSelection(1);
       resetSearchFields();
     } else {
       _screenerSearchResults
           .getRowsPerPageSelector()
           .setSelection(_screenerSearchResults.getRowsPerPageSelector().getDefaultSelection());
       resetSearchFields();
     }
     return BROWSE_SCREENERS;
   } else {
     showMessage("users.screenerNameRequired");
   }
   return REDISPLAY_PAGE_ACTION_RESULT;
 }
 public Object getAsObject(FacesContext arg0, UIComponent arg1, String value)
     throws ConverterException {
   if (StringUtils.isEmpty(value)) {
     return null;
   }
   value = value.trim();
   if (value.toUpperCase().startsWith(PMCID_PREFIX)) {
     value = value.substring(3);
   }
   return Integer.parseInt(value);
 }
Пример #4
0
  private void initialize() {
    _relatedBeanClass =
        (Class<? extends AbstractEntity>) _propertyDescriptor.getReadMethod().getReturnType();
    // if this property is a collection property, then we must determine the
    // related property by looking at the parameterized type of the collection!
    if (Collection.class.isAssignableFrom(_relatedBeanClass)) {
      Type genericReturnType = _propertyDescriptor.getReadMethod().getGenericReturnType();
      if (genericReturnType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) genericReturnType;
        _relatedBeanClass = (Class) parameterizedType.getActualTypeArguments()[0];
        if (!AbstractEntity.class.isAssignableFrom(_relatedBeanClass)) {
          // collection property does not have to be for an entity relationship!
          _relatedBeanClass = null;
          return;
        }
      } else {
        _relatedBeanClass = null;
        return;
      }
    }
    try {
      _relatedBeanInfo = Introspector.getBeanInfo(_relatedBeanClass);
    } catch (IntrospectionException e) {
      return;
    }

    // TODO: if unidirectional from this side, no need to calculate related property info, below.

    // TODO: see which annotation checks below are really necessary

    javax.persistence.OneToMany jpaOneToMany =
        _propertyDescriptor.getReadMethod().getAnnotation(javax.persistence.OneToMany.class);
    ToOne toOne = _propertyDescriptor.getReadMethod().getAnnotation(ToOne.class);
    ToMany toMany = _propertyDescriptor.getReadMethod().getAnnotation(ToMany.class);
    if (jpaOneToMany != null && jpaOneToMany.mappedBy().length() > 0) {
      _relatedPropertyName = jpaOneToMany.mappedBy();
      _relatedPropertyDescriptor =
          findRelatedPropertyDescriptor(_relatedBeanInfo, _relatedPropertyName);
    } else if (toOne != null && toOne.inverseProperty().length() > 0) {
      _relatedPropertyName = toOne.inverseProperty();
      _relatedPropertyDescriptor =
          findRelatedPropertyDescriptor(_relatedBeanInfo, _relatedPropertyName);
    } else if (toMany != null && toMany.inverseProperty().length() > 0) {
      _relatedPropertyName = toMany.inverseProperty();
      _relatedPropertyDescriptor =
          findRelatedPropertyDescriptor(_relatedBeanInfo, _relatedPropertyName);
    } else {
      _relatedPropertyName =
          StringUtils.uncapitalize(
              _propertyDescriptor.getReadMethod().getDeclaringClass().getSimpleName());
      _relatedPropertyDescriptor =
          findRelatedPropertyDescriptor(_relatedBeanInfo, _relatedPropertyName);
      if (_relatedPropertyDescriptor == null) {
        _relatedPropertyName = _relatedPropertyName + "s";
        _relatedPropertyDescriptor =
            findRelatedPropertyDescriptor(_relatedBeanInfo, _relatedPropertyName);
      }
    }

    if (_relatedPropertyDescriptor != null) {
      if (Collection.class.isAssignableFrom(
          _relatedPropertyDescriptor.getReadMethod().getReturnType())) {
        _relatedSideIsToMany = true;
      } else if (Map.class.isAssignableFrom(
          _relatedPropertyDescriptor.getReadMethod().getReturnType())) {
        _relatedSideIsMappedToMany = true;
      }
    }
  }