Java Code Examples for org.apache.commons.beanutils.PropertyUtils#getProperty()
The following examples show how to use
org.apache.commons.beanutils.PropertyUtils#getProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataDictionaryLookupResultsSupportStrategy.java From rice with Educational Community License v2.0 | 6 votes |
/** * Converts a Map of PKFields into a String lookup ID * @param pkFieldNames the name of the PK fields, which should be converted to the given lookupId * @param businessObjectClass the class of the business object getting the primary key * @return the String lookup id */ protected String convertPKFieldMapToLookupId(List<String> pkFieldNames, BusinessObject businessObject) { StringBuilder lookupId = new StringBuilder(); for (String pkFieldName : pkFieldNames) { try { final Object value = PropertyUtils.getProperty(businessObject, pkFieldName); if (value != null) { lookupId.append(pkFieldName); lookupId.append("-"); final Formatter formatter = retrieveBestFormatter(pkFieldName, businessObject.getClass()); final String formattedValue = (formatter != null) ? formatter.format(value).toString() : value.toString(); lookupId.append(formattedValue); } lookupId.append(SearchOperator.OR.op()); } catch (IllegalAccessException iae) { throw new RuntimeException("Could not retrieve pk field value "+pkFieldName+" from business object "+businessObject.getClass().getName(), iae); } catch (InvocationTargetException ite) { throw new RuntimeException("Could not retrieve pk field value "+pkFieldName+" from business object "+businessObject.getClass().getName(), ite); } catch (NoSuchMethodException nsme) { throw new RuntimeException("Could not retrieve pk field value "+pkFieldName+" from business object "+businessObject.getClass().getName(), nsme); } } return lookupId.substring(0, lookupId.length() - 1); // kill the last "|" }
Example 2
Source File: OkrWorkReportPersonLinkService.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
/** * 上一页 * @param id * @param count * @param wrapIn * @return * @throws Exception */ public List<OkrWorkReportPersonLink> listPrevWithFilter( String id, Integer count, WorkPersonSearchFilter wrapIn ) throws Exception { Business business = null; Object sequence = null; List<OkrWorkReportPersonLink> okrWorkReportPersonLinkList = new ArrayList<OkrWorkReportPersonLink>(); if( count == null ){ count = 20; } if( wrapIn == null ){ throw new Exception( "wrapIn is null!" ); } try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { business = new Business(emc); if( id != null && !"(0)".equals(id) && id.trim().length() > 20 ){ if (!StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find( id, OkrWorkReportPersonLink.class ), JpaObject.sequence_FIELDNAME ); } } okrWorkReportPersonLinkList = business.okrWorkReportPersonLinkFactory().listPrevWithFilter( id, count, sequence, wrapIn ); } catch ( Exception e ) { throw e; } return okrWorkReportPersonLinkList; }
Example 3
Source File: OkrWorkDynamicsService.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
/** * 查询上一页的信息数据,直接调用Factory里的方法 * @param id * @param count * @param sequence * @param wrapIn * @return * @throws Exception */ public List<OkrWorkDynamics> listDynamicPrevWithFilter( String id, Integer count, List<String> centerIds, List<String> workIds, String sequenceField, String order, Boolean isOkrSystemAdmin ) throws Exception { Business business = null; Object sequence = null; try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { business = new Business(emc); if( id != null && !"(0)".equals(id) && id.trim().length() > 20 ){ if (!StringUtils.equalsIgnoreCase( id,StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find( id, OkrWorkDynamics.class ), JpaObject.sequence_FIELDNAME ); } } return business.okrWorkDynamicsFactory().listPrevWithFilter( id, count, sequence, centerIds, workIds, sequenceField, order, isOkrSystemAdmin ); } catch ( Exception e ) { throw e; } }
Example 4
Source File: ExpressUtil.java From QLExpress with Apache License 2.0 | 6 votes |
public static Object getProperty(Object bean, Object name) { try { if(bean==null && QLExpressRunStrategy.isAvoidNullPointer()){ return null; } if(bean.getClass().isArray() && name.equals("length")){ return Array.getLength(bean); }else if (bean instanceof Class) { if(name.equals("class")){ return bean; }else{ Field f = ((Class<?>) bean).getDeclaredField(name.toString()); return f.get(null); } }else if(bean instanceof Map ){ return ((Map<?,?>)bean).get(name); }else { Object obj = PropertyUtils.getProperty(bean, name.toString()); return obj; } } catch (Exception e) { throw new RuntimeException(e); } }
Example 5
Source File: LabeledInputField.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private Map getMap(Object object, String field){ if (object instanceof PersistentObject) { return ((PersistentObject) object).getMap(field); } else { try { Object value = PropertyUtils.getProperty(object, field); if (value instanceof Map) { return (Map) value; } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LoggerFactory.getLogger(getClass()) .error("Error getting map property [" + field + "] of [" + object + "]", e); } } return null; }
Example 6
Source File: RestServer.java From zstack with Apache License 2.0 | 6 votes |
private void writeResponse(ApiResponse response, RestResponseWrapper w, Object replyOrEvent) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { if (!w.annotation.allTo().equals("")) { response.put(w.annotation.allTo(), PropertyUtils.getProperty(replyOrEvent, w.annotation.allTo())); } else { for (Map.Entry<String, String> e : w.responseMappingFields.entrySet()) { response.put(e.getKey(), PropertyUtils.getProperty(replyOrEvent, e.getValue())); } } // TODO: fix hard code hack if (APIQueryReply.class.isAssignableFrom(w.apiResponseClass)) { Object total = PropertyUtils.getProperty(replyOrEvent, "total"); if (total != null) { response.put("total", total); } } if (requestInfo.get().headers.containsKey(RestConstants.HEADER_JSON_SCHEMA) // set schema anyway if it's a query API || APIQueryReply.class.isAssignableFrom(w.apiResponseClass)) { response.setSchema(new JsonSchemaBuilder(response).build()); } }
Example 7
Source File: JListBinding.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
public void put(IValidatable bean) { try { DefaultListModel model = new DefaultListModel(); List<?> list = (List<?>) PropertyUtils.getProperty(bean, _property); if (list != null) { for (Object o : list) { model.addElement(o); } } _list.setModel(model); } catch (Exception e) { throw new BindingException(e); } }
Example 8
Source File: BeanUtils.java From zstack with Apache License 2.0 | 6 votes |
private static Object getProperty(Object bean, Iterator<String> it) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { String path = it.next(); if (bean instanceof Map) { Pattern re = Pattern.compile("(.*)\\[(\\d+)]"); Matcher m = re.matcher(path); if (m.find()) { path = String.format("(%s)[%s]", m.group(1), m.group(2)); } } Object val = PropertyUtils.getProperty(bean, path); if (it.hasNext()) { return getProperty(val, it); } else { return val; } }
Example 9
Source File: JTextAreaBinding.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
public void put(IValidatable bean) { try { List<?> list = (List<?>) PropertyUtils.getProperty(bean, _property); StringBuffer sb = new StringBuffer(); if (list != null) { for (int i = 0; i < list.size(); i++) { sb.append(list.get(i)); if (i < list.size() - 1) { sb.append("\n"); } } } _textArea.setText(sb.toString()); } catch (Exception e) { throw new BindingException(e); } }
Example 10
Source File: TestStandardBullhornApiRestAssociations.java From sdk-rest with MIT License | 6 votes |
@Test public void testAssociateNote() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Note entity = bullhornData.findEntity(Note.class, testEntities.getNoteId(), getAssociationFieldSet(AssociationFactory.noteAssociations())); for (AssociationField<Note, ? extends BullhornEntity> association : AssociationFactory.noteAssociations().allAssociations()) { Set<Integer> associationIds = new HashSet<Integer>(); OneToMany<? extends BullhornEntity> linkedIds = (OneToMany<? extends BullhornEntity>) PropertyUtils.getProperty(entity, association.getAssociationFieldName()); if (linkedIds != null && !linkedIds.getData().isEmpty()) { associationIds.add(linkedIds.getData().get(0).getId()); testAssociation(Note.class, testEntities.getNoteId(), associationIds, association); } } }
Example 11
Source File: TestStandardBullhornApiRestAssociations.java From sdk-rest with MIT License | 6 votes |
@Test public void testAssociateClientContact() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { ClientContact entity = bullhornData.findEntity(ClientContact.class, testEntities.getClientContactId(), getAssociationFieldSet(AssociationFactory.clientContactAssociations())); for (AssociationField<ClientContact, ? extends BullhornEntity> association : AssociationFactory.clientContactAssociations() .allAssociations()) { Set<Integer> associationIds = new HashSet<Integer>(); OneToMany<? extends BullhornEntity> linkedIds = (OneToMany<? extends BullhornEntity>) PropertyUtils.getProperty(entity, association.getAssociationFieldName()); if (linkedIds != null && !linkedIds.getData().isEmpty()) { associationIds.add(linkedIds.getData().get(0).getId()); testAssociation(ClientContact.class, testEntities.getClientContactId(), associationIds, association); } } }
Example 12
Source File: OkrWorkDynamicsService.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
/** * 查询下一页的信息数据,直接调用Factory里的方法 * @param id * @param count * @param sequence * @param wrapIn * @return * @throws Exception */ public List<OkrWorkDynamics> listDynamicNextWithFilter( String id, Integer count, List<String> centerIds, List<String> workIds, String sequenceField, String order, Boolean isOkrSystemAdmin ) throws Exception { Business business = null; Object sequence = null; try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { business = new Business(emc); if( id != null && !"(0)".equals(id) && id.trim().length() > 20 ){ if (!StringUtils.equalsIgnoreCase( id,StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find( id, OkrWorkDynamics.class ), JpaObject.sequence_FIELDNAME ); } } return business.okrWorkDynamicsFactory().listNextWithFilter( id, count, sequence, centerIds, workIds, sequenceField, order, isOkrSystemAdmin ); } catch ( Exception e ) { throw e; } }
Example 13
Source File: OptJTextAreaBinding.java From PyramidShader with GNU General Public License v3.0 | 6 votes |
public void put(IValidatable bean) { try { boolean selected = "true".equals(BeanUtils.getProperty(bean, _stateProperty)); _button.setSelected(selected); _textArea.setEnabled(selected); List<?> list = (List<?>) PropertyUtils.getProperty(bean, _property); StringBuffer sb = new StringBuffer(); if (list != null) { for (int i = 0; i < list.size(); i++) { sb.append(list.get(i)); if (i < list.size() - 1) { sb.append("\n"); } } } _textArea.setText(sb.toString()); } catch (Exception e) { throw new BindingException(e); } }
Example 14
Source File: OkrCenterWorkQueryService.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
/** * 查询下一页的信息数据,直接调用Factory里的方法 * @param id * @param count * @param sequence * @param wrapIn * @return * @throws Exception */ public List<OkrCenterWorkInfo> listNextWithFilter( String id, Integer count, WorkCommonQueryFilter wrapIn ) throws Exception { Business business = null; Object sequence = null; try ( EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { business = new Business(emc); if( id != null && !"(0)".equals(id) && id.trim().length() > 20 ){ if ( !StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find( id, OkrCenterWorkInfo.class ), JpaObject.sequence_FIELDNAME ); } } return business.okrCenterWorkInfoFactory().listNextWithFilter(id, count, sequence, wrapIn); } catch ( Exception e ) { throw e; } }
Example 15
Source File: KoubachiBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * @{inheritDoc} */ @Override protected void execute() { List<Device> devices = getDevices(apiDeviceListUrl, credentials, appKey); List<Plant> plants = getPlants(apiPlantListUrl, credentials, appKey); for (KoubachiBindingProvider provider : providers) { for (String itemName : provider.getItemNames()) { if (provider.isCareAction(itemName)) { continue; // nothing to do for care actions } KoubachiResourceType resourceType = provider.getResourceType(itemName); String resourceId = provider.getResourceId(itemName); String propertyName = provider.getPropertyName(itemName); KoubachiResource resource = null; if (KoubachiResourceType.DEVICE.equals(resourceType)) { resource = findResource(resourceId, devices); } else { resource = findResource(resourceId, plants); } if (resource == null) { logger.debug("Cannot find Koubachi resource with id '{}'", resourceId); continue; } try { Object propertyValue = PropertyUtils.getProperty(resource, propertyName); State state = createState(propertyValue); if (state != null) { eventPublisher.postUpdate(itemName, state); } } catch (Exception e) { logger.warn("Reading value '{}' from Resource '{}' throws went wrong", propertyName, resource); } } } }
Example 16
Source File: JComboBoxBinding.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
public void put(IValidatable bean) { try { Integer i = (Integer) PropertyUtils.getProperty(bean, _property); if (i == null) { throw new BindingException( Messages.getString("JComboBoxBinding.property.null")); } select(i.intValue()); } catch (Exception e) { throw new BindingException(e); } }
Example 17
Source File: ActionListStdForTopUnitPrevWithFilter.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement ) throws Exception { ActionResult<List<Wo>> result = new ActionResult<>(); List<Wo> wraps = null; EffectivePerson currentPerson = this.effectivePerson(request); long total = 0; List<StatisticTopUnitForDay> statisticList = null; WrapInFilterStatisticTopUnitForDay wrapIn = null; Boolean check = true; try { wrapIn = this.convertToWrapIn( jsonElement, WrapInFilterStatisticTopUnitForDay.class ); } catch (Exception e ) { check = false; Exception exception = new ExceptionWrapInConvert( e, jsonElement ); result.error( exception ); logger.error( e, currentPerson, request, null); } if(check ){ try { EntityManagerContainer emc = EntityManagerContainerFactory.instance().create(); Business business = new Business(emc); // 查询出ID对应的记录的sequence Object sequence = null; if (id == null || "(0)".equals(id) || id.isEmpty()) { } else { if (!StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find(id, StatisticTopUnitForDay.class ), JpaObject.sequence_FIELDNAME); } } //将下级组织的数据纳入组织统计数据查询范围 List<String> unitNameList = getUnitNameList(wrapIn.getTopUnitName(), wrapIn.getUnitName(), effectivePerson.getDebugger() ); wrapIn.setUnitName(unitNameList); // 从数据库中查询符合条件的一页数据对象 statisticList = business.getStatisticTopUnitForDayFactory().listIdsPrevWithFilter(id, count, sequence, wrapIn); // 从数据库中查询符合条件的对象总数 total = business.getStatisticTopUnitForDayFactory().getCountWithFilter(wrapIn); // 将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象 wraps = Wo.copier.copy(statisticList); } catch (Throwable th) { th.printStackTrace(); result.error(th); } } result.setCount(total); result.setData(wraps); return result; }
Example 18
Source File: ActionListNextWithFilter.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
protected ActionResult<List<Wo>> execute(HttpServletRequest request, EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement) throws Exception { ActionResult<List<Wo>> result = new ActionResult<>(); List<Wo> wraps = null; Long total = 0L; List<AttendanceAppealInfo> detailList = null; WrapInFilterAppeal wrapIn = null; Boolean check = true; try { wrapIn = this.convertToWrapIn(jsonElement, WrapInFilterAppeal.class); } catch (Exception e) { check = false; Exception exception = new ExceptionWrapInConvert(e, jsonElement); result.error(exception); logger.error(e, effectivePerson, request, null); } if (check) { try { EntityManagerContainer emc = EntityManagerContainerFactory.instance().create(); Business business = new Business(emc); // 查询出ID对应的记录的sequence Object sequence = null; if (id == null || "(0)".equals(id) || id.isEmpty()) { logger.debug(effectivePerson, ">>>>>>>>>>第一页查询,没有id传入"); } else { if (!StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty(emc.find(id, AttendanceAppealInfo.class), JpaObject.sequence_FIELDNAME); } } // 从数据库中查询符合条件的一页数据对象 detailList = business.getAttendanceAppealInfoFactory().listIdsNextWithFilter(id, count, sequence, wrapIn); // 从数据库中查询符合条件的对象总数 total = business.getAttendanceAppealInfoFactory().getCountWithFilter(wrapIn); // 将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象 wraps = Wo.copier.copy(detailList); // 对查询的列表进行排序 result.setCount(total); } catch (Throwable th) { th.printStackTrace(); result.error(th); } } result.setData(wraps); return result; }
Example 19
Source File: ActionListStmForTopUnitNextWithFilter.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement ) throws Exception { ActionResult<List<Wo>> result = new ActionResult<>(); List<Wo> wraps = null; EffectivePerson currentPerson = this.effectivePerson(request); long total = 0; List<StatisticTopUnitForMonth> statisticList = null; WrapInFilterStatisticTopUnitForMonth wrapIn = null; Boolean check = true; try { wrapIn = this.convertToWrapIn( jsonElement, WrapInFilterStatisticTopUnitForMonth.class ); } catch (Exception e ) { check = false; Exception exception = new ExceptionWrapInConvert( e, jsonElement ); result.error( exception ); logger.error( e, currentPerson, request, null); } if(check ){ try { EntityManagerContainer emc = EntityManagerContainerFactory.instance().create(); Business business = new Business(emc); // 查询出ID对应的记录的sequence Object sequence = null; if (id == null || "(0)".equals(id) || id.isEmpty()) { } else { if (!StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find(id, StatisticTopUnitForMonth.class ), JpaObject.sequence_FIELDNAME); } } //将下级组织的数据纳入组织统计数据查询范围 List<String> unitNameList = getUnitNameList(wrapIn.getTopUnitName(), wrapIn.getUnitName(), effectivePerson.getDebugger() ); wrapIn.setUnitName(unitNameList); // 从数据库中查询符合条件的一页数据对象 statisticList = business.getStatisticTopUnitForMonthFactory().listIdsNextWithFilter(id, count, sequence, wrapIn); // 从数据库中查询符合条件的对象总数 total = business.getStatisticTopUnitForMonthFactory().getCountWithFilter(wrapIn); // 将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象 wraps = Wo.copier.copy( statisticList ); } catch (Throwable th) { th.printStackTrace(); result.error(th); } } result.setCount(total); result.setData(wraps); return result; }
Example 20
Source File: ActionListStmForPersonNextWithFilter.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String id, Integer count, JsonElement jsonElement ) throws Exception { ActionResult<List<Wo>> result = new ActionResult<>(); List<Wo> wraps = null; EffectivePerson currentPerson = this.effectivePerson(request); long total = 0; List<StatisticPersonForMonth> statisticList = null; WrapInFilterStatisticPersonForMonth wrapIn = null; Boolean check = true; try { wrapIn = this.convertToWrapIn( jsonElement, WrapInFilterStatisticPersonForMonth.class ); } catch (Exception e ) { check = false; Exception exception = new ExceptionWrapInConvert( e, jsonElement ); result.error( exception ); logger.error( e, currentPerson, request, null); } if(check ){ try { EntityManagerContainer emc = EntityManagerContainerFactory.instance().create(); Business business = new Business(emc); // 查询出ID对应的记录的sequence Object sequence = null; if (id == null || "(0)".equals(id) || id.isEmpty()) { } else { if (!StringUtils.equalsIgnoreCase(id, StandardJaxrsAction.EMPTY_SYMBOL)) { sequence = PropertyUtils.getProperty( emc.find(id, StatisticPersonForMonth.class ), JpaObject.sequence_FIELDNAME); } } //将下级组织的数据纳入组织统计数据查询范围 List<String> unitNameList = getUnitNameList(wrapIn.getTopUnitName(), wrapIn.getUnitName(), effectivePerson.getDebugger() ); wrapIn.setUnitName(unitNameList); // 从数据库中查询符合条件的一页数据对象 statisticList = business.getStatisticPersonForMonthFactory().listIdsNextWithFilter(id, count, sequence, wrapIn); // 从数据库中查询符合条件的对象总数 total = business.getStatisticPersonForMonthFactory().getCountWithFilter(wrapIn); // 将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象 wraps = Wo.copier.copy(statisticList); } catch (Throwable th) { th.printStackTrace(); result.error(th); } } result.setCount(total); result.setData(wraps); return result; }