List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:io.github.moosbusch.lumpi.gui.form.editor.io.spi.ListButtonStoreValueDelegate.java
@SuppressWarnings("unchecked") @Override/*from ww w. j a va 2 s . c o m*/ public void storeValue(Object context) { if (context != null) { ListButton listButton = getFormEditor().getComponent(); String propertyName = listButton.getListDataKey(); ListView.ListDataBindMapping bindMapping = listButton.getListDataBindMapping(); Object newPropertyValue = bindMapping.valueOf(listButton.getListData()); if (PropertyUtils.isWriteable(context, propertyName)) { listButton.store(context); } else { Object oldPropertyValue = null; try { oldPropertyValue = PropertyUtils.getProperty(context, propertyName); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(AbstractDynamicForm.class.getName()).log(Level.SEVERE, null, ex); } finally { if ((newPropertyValue != null) && (oldPropertyValue != null)) { if ((newPropertyValue instanceof java.util.Collection) && (oldPropertyValue instanceof java.util.Collection)) { java.util.Collection<Object> newColl = (java.util.Collection<Object>) newPropertyValue; java.util.Collection<Object> oldColl = (java.util.Collection<Object>) oldPropertyValue; newColl.stream().filter((obj) -> (!oldColl.contains(obj))).forEach((obj) -> { oldColl.add(obj); }); } else if ((newPropertyValue instanceof Sequence) && (oldPropertyValue instanceof Sequence)) { Sequence<Object> newSeq = (Sequence<Object>) newPropertyValue; Sequence<Object> oldSeq = (Sequence<Object>) oldPropertyValue; for (int cnt = 0; cnt < newSeq.getLength(); cnt++) { Object obj = newSeq.get(cnt); if (oldSeq.indexOf(obj) == -1) { oldSeq.add(obj); } } } else if ((newPropertyValue instanceof org.apache.pivot.collections.Set) && (oldPropertyValue instanceof org.apache.pivot.collections.Set)) { org.apache.pivot.collections.Set<Object> newColl = (org.apache.pivot.collections.Set<Object>) newPropertyValue; org.apache.pivot.collections.Set<Object> oldColl = (org.apache.pivot.collections.Set<Object>) oldPropertyValue; for (Object obj : newColl) { if (!oldColl.contains(obj)) { oldColl.add(obj); } } } else if ((ObjectUtils.isArray(newPropertyValue)) && (ObjectUtils.isArray(oldPropertyValue))) { Object[] newArray = (Object[]) newPropertyValue; Object[] oldArray = (Object[]) oldPropertyValue; for (Object obj : newArray) { if (!ArrayUtils.contains(oldArray, obj)) { oldArray = ArrayUtils.add(oldArray, obj); } } } } } } } }
From source file:com.esofthead.mycollab.core.persistence.service.DefaultCrudService.java
@Override public int saveWithSession(T record, String username) { if (!StringUtils.isBlank(username)) { try {/*from w ww . j a v a2 s.c o m*/ PropertyUtils.setProperty(record, "createduser", username); } catch (Exception e) { } } try { PropertyUtils.setProperty(record, "createdtime", new GregorianCalendar().getTime()); PropertyUtils.setProperty(record, "lastupdatedtime", new GregorianCalendar().getTime()); } catch (Exception e) { } getCrudMapper().insertAndReturnKey(record); try { return (Integer) PropertyUtils.getProperty(record, "id"); } catch (Exception e) { return 0; } }
From source file:com.mycollab.module.crm.ui.components.PeopleInfoComp.java
public void displayEntryPeople(ValuedBean bean) { this.removeAllComponents(); this.withMargin(false); Label peopleInfoHeader = new Label( FontAwesome.USER.getHtml() + " " + UserUIContext.getMessage(CrmCommonI18nEnum.SUB_INFO_PEOPLE), ContentMode.HTML);/* w w w .j a v a 2 s . co m*/ peopleInfoHeader.setStyleName("info-hdr"); this.addComponent(peopleInfoHeader); GridLayout layout = new GridLayout(2, 2); layout.setSpacing(true); layout.setWidth("100%"); layout.setMargin(new MarginInfo(false, false, false, true)); try { Label createdLbl = new Label(UserUIContext.getMessage(CrmCommonI18nEnum.ITEM_CREATED_PEOPLE)); createdLbl.setSizeUndefined(); layout.addComponent(createdLbl, 0, 0); String createdUserName = (String) PropertyUtils.getProperty(bean, "createduser"); String createdUserAvatarId = (String) PropertyUtils.getProperty(bean, "createdUserAvatarId"); String createdUserDisplayName = (String) PropertyUtils.getProperty(bean, "createdUserFullName"); UserLink createdUserLink = new UserLink(createdUserName, createdUserAvatarId, createdUserDisplayName); layout.addComponent(createdUserLink, 1, 0); layout.setColumnExpandRatio(1, 1.0f); Label assigneeLbl = new Label(UserUIContext.getMessage(CrmCommonI18nEnum.ITEM_ASSIGN_PEOPLE)); assigneeLbl.setSizeUndefined(); layout.addComponent(assigneeLbl, 0, 1); String assignUserName = (String) PropertyUtils.getProperty(bean, "assignuser"); String assignUserAvatarId = (String) PropertyUtils.getProperty(bean, "assignUserAvatarId"); String assignUserDisplayName = (String) PropertyUtils.getProperty(bean, "assignUserFullName"); UserLink assignUserLink = new UserLink(assignUserName, assignUserAvatarId, assignUserDisplayName); layout.addComponent(assignUserLink, 1, 1); } catch (Exception e) { LOG.error("Can not build user link {} ", BeanUtility.printBeanObj(bean)); } this.addComponent(layout); }
From source file:com.mycollab.aspect.MonitorItemAspect.java
@AfterReturning("execution(public * com.mycollab..service..*.saveWithSession(..)) && args(bean, username)") public void traceSaveActivity(JoinPoint joinPoint, Object bean, String username) { Advised advised = (Advised) joinPoint.getThis(); Class<?> cls = advised.getTargetSource().getTargetClass(); try {//w w w . ja v a 2 s . c om Watchable watchableAnnotation = cls.getAnnotation(Watchable.class); if (watchableAnnotation != null) { int sAccountId = (Integer) PropertyUtils.getProperty(bean, "saccountid"); int typeId = (Integer) PropertyUtils.getProperty(bean, "id"); Integer extraTypeId = null; if (!"".equals(watchableAnnotation.extraTypeId())) { extraTypeId = (Integer) PropertyUtils.getProperty(bean, watchableAnnotation.extraTypeId()); } MonitorItem monitorItem = new MonitorItem(); monitorItem.setMonitorDate(new GregorianCalendar().getTime()); monitorItem.setType(ClassInfoMap.getType(cls)); monitorItem.setTypeid(typeId); monitorItem.setExtratypeid(extraTypeId); monitorItem.setUser(username); monitorItem.setSaccountid(sAccountId); monitorItemService.saveWithSession(monitorItem, username); if (!watchableAnnotation.userFieldName().equals("")) { String moreUser = (String) PropertyUtils.getProperty(bean, watchableAnnotation.userFieldName()); if (moreUser != null && !moreUser.equals(username)) { monitorItem.setId(null); monitorItem.setUser(moreUser); monitorItemService.saveWithSession(monitorItem, moreUser); } } } Traceable traceAnnotation = cls.getAnnotation(Traceable.class); if (traceAnnotation != null) { int sAccountId = (Integer) PropertyUtils.getProperty(bean, "saccountid"); int typeId = (Integer) PropertyUtils.getProperty(bean, "id"); RelayEmailNotificationWithBLOBs relayNotification = new RelayEmailNotificationWithBLOBs(); relayNotification.setChangeby(username); relayNotification.setChangecomment(""); relayNotification.setSaccountid(sAccountId); relayNotification.setType(ClassInfoMap.getType(cls)); relayNotification.setAction(MonitorTypeConstants.CREATE_ACTION); relayNotification.setTypeid("" + typeId); relayEmailNotificationService.saveWithSession(relayNotification, username); // Save notification item } } catch (Exception e) { LOG.error("Error when save relay email notification for save action of service " + cls.getName(), e); } }
From source file:jp.co.ctc_g.jse.core.validation.constraints.feature.equalsto.EqualsToValidator.java
/** * {@inheritDoc}// w ww .j a v a2 s . com */ @Override public boolean isValid(Object suspect, ConstraintValidatorContext context) { Object f = null; Object t = null; try { f = PropertyUtils.getProperty(suspect, equalsTo.from()); t = PropertyUtils.getProperty(suspect, equalsTo.to()); } catch (IllegalAccessException e) { if (L.isDebugEnabled()) { L.debug(Strings.substitute(R.getString("D-VALIDATOR-EQUALS-TO#0001"), Maps.hash("from", equalsTo.from()).map("to", equalsTo.to()).map("target", suspect.getClass().getSimpleName()))); } throw new InternalException(AfterValidator.class, "E-VALIDATOR-EQUALS-TO#0001", e); } catch (InvocationTargetException e) { if (L.isDebugEnabled()) { L.debug(Strings.substitute(R.getString("D-VALIDATOR-EQUALS-TO#0002"), Maps.hash("from", equalsTo.from()).map("to", equalsTo.to()).map("target", suspect.getClass().getSimpleName()))); } throw new InternalException(AfterValidator.class, "E-VALIDATOR-EQUALS-TO#0002", e); } catch (NoSuchMethodException e) { if (L.isDebugEnabled()) { L.debug(Strings.substitute(R.getString("D-VALIDATOR-EQUALS-TO#0003"), Maps.hash("from", equalsTo.from()).map("to", equalsTo.to()).map("target", suspect.getClass().getSimpleName()))); } throw new InternalException(AfterValidator.class, "E-VALIDATOR-EQUALS-TO#0003", e); } if (f == null || t == null) return true; return Validators.equalsTo(f, t) ? true : addErrors(context); }
From source file:com.esofthead.mycollab.mobile.module.crm.ui.RelatedReadItemField.java
@Override protected Component initContent() { try {/*from www . j a va2 s .co m*/ final String type = (String) PropertyUtils.getProperty(RelatedReadItemField.this.bean, "type"); if (type == null || type.equals("")) { return new Label(""); } final Integer typeid = (Integer) PropertyUtils.getProperty(bean, "typeid"); if (typeid == null) { return new Label(""); } Resource relatedLink = null; String relateItemName = null; if ("Account".equals(type)) { AccountService accountService = ApplicationContextUtil.getSpringBean(AccountService.class); final SimpleAccount account = accountService.findById(typeid, AppContext.getAccountId()); if (account != null) { relateItemName = account.getAccountname(); relatedLink = MyCollabResource.newResource("icons/16/crm/account.png"); } } else if ("Campaign".equals(type)) { CampaignService campaignService = ApplicationContextUtil.getSpringBean(CampaignService.class); final SimpleCampaign campaign = campaignService.findById(typeid, AppContext.getAccountId()); if (campaign != null) { relateItemName = campaign.getCampaignname(); relatedLink = MyCollabResource.newResource("icons/16/crm/campaign.png"); } } else if ("Contact".equals(type)) { ContactService contactService = ApplicationContextUtil.getSpringBean(ContactService.class); final SimpleContact contact = contactService.findById(typeid, AppContext.getAccountId()); if (contact != null) { relateItemName = contact.getContactName(); relatedLink = MyCollabResource.newResource("icons/16/crm/contact.png"); } } else if ("Lead".equals(type)) { LeadService leadService = ApplicationContextUtil.getSpringBean(LeadService.class); final SimpleLead lead = leadService.findById(typeid, AppContext.getAccountId()); if (lead != null) { relateItemName = lead.getLeadName(); relatedLink = MyCollabResource.newResource("icons/16/crm/lead.png"); } } else if ("Opportunity".equals(type)) { OpportunityService opportunityService = ApplicationContextUtil .getSpringBean(OpportunityService.class); final SimpleOpportunity opportunity = opportunityService.findById(typeid, AppContext.getAccountId()); if (opportunity != null) { relateItemName = opportunity.getOpportunityname(); relatedLink = MyCollabResource.newResource("icons/16/crm/opportunity.png"); } } else if ("Case".equals(type)) { CaseService caseService = ApplicationContextUtil.getSpringBean(CaseService.class); final SimpleCase cases = caseService.findById(typeid, AppContext.getAccountId()); if (cases != null) { relateItemName = cases.getSubject(); relatedLink = MyCollabResource.newResource("icons/16/crm/case.png"); } } Button related = new Button(relateItemName); if (relatedLink != null) related.setIcon(relatedLink); if (relatedLink != null) { return related; } else { return new Label(""); } } catch (Exception e) { return new Label(""); } }
From source file:jp.co.ctc_g.jse.core.validation.constraints.feature.before.BeforeValidator.java
/** * {@inheritDoc}// ww w . j ava 2s . c o m */ @Override public boolean isValid(Object suspect, ConstraintValidatorContext context) { Object f = null; Object t = null; try { f = PropertyUtils.getProperty(suspect, before.from()); t = PropertyUtils.getProperty(suspect, before.to()); } catch (IllegalAccessException e) { if (L.isDebugEnabled()) { L.debug(Strings.substitute(R.getString("D-VALIDATOR-BEFORE#0001"), Maps.hash("from", before.from()) .map("to", before.to()).map("target", suspect.getClass().getSimpleName()))); } throw new InternalException(AfterValidator.class, "E-VALIDATOR-BEFORE#0001", e); } catch (InvocationTargetException e) { if (L.isDebugEnabled()) { L.debug(Strings.substitute(R.getString("D-VALIDATOR-BEFORE#0002"), Maps.hash("from", before.from()) .map("to", before.to()).map("target", suspect.getClass().getSimpleName()))); } throw new InternalException(AfterValidator.class, "E-VALIDATOR-BEFORE#0002", e); } catch (NoSuchMethodException e) { if (L.isDebugEnabled()) { L.debug(Strings.substitute(R.getString("D-VALIDATOR-BEFORE#0003"), Maps.hash("from", before.from()) .map("to", before.to()).map("target", suspect.getClass().getSimpleName()))); } throw new InternalException(AfterValidator.class, "E-VALIDATOR-BEFORE#0003", e); } if (f == null || t == null) return true; return Validators.before(Validators.toDate(f, before.pattern()), Validators.toDate(t, before.pattern())) ? true : addErrors(context); }
From source file:com.khubla.cbean.serializer.impl.json.JSONListFieldSerializer.java
@Override public void delete(Object o, Field field) throws SerializerException { final Property property = field.getAnnotation(Property.class); if ((null != property) && (property.cascadeDelete() == true)) { try {/*from w w w . jav a2 s. c o m*/ /* * get the parameterized type */ final ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType(); final Class<?> containedType = (Class<?>) parameterizedType.getActualTypeArguments()[0]; /* * get cBean */ final CBean<Object> cBean = CBeanServer.getInstance().getCBean(containedType); /* * get the array object */ @SuppressWarnings("unchecked") final List<Object> list = (List<Object>) PropertyUtils.getProperty(o, field.getName()); /* * iterate */ for (final Object obj : list) { final String key = cBean.getId(obj); cBean.delete(new CBeanKey(key)); } } catch (final Exception e) { throw new SerializerException(e); } } }
From source file:com.troyhisted.inputfield.util.DynaListTest.java
/** * Verify a {@link DynaField} works properly with a {@link DynaList}. * * @throws IllegalAccessException//from w w w . j a v a 2 s .com * @throws InvocationTargetException * @throws NoSuchMethodException */ @Test public void testDynaListInDynaField() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Field<? extends List<Direction>> field = DynaField.initialize(DynaList.construct(Direction.class)); BeanUtils.setProperty(field, "value.[0]", "South"); Assert.assertEquals(Direction.South, field.getValue().get(0)); Assert.assertEquals(Direction.South, PropertyUtils.getProperty(field, "value.[0]")); }
From source file:net.jcreate.e3.table.model.MapDataModel.java
/** * ?//w w w .java 2s . c om * @param pItem next? * @param pProperty ?? * @return ? */ public Object getCellValue(Object pItem, String pProperty) { if (pItem == null) { return null; } Object itemValue = null; java.util.Map.Entry entry = (java.util.Map.Entry) pItem; Object row = entry.getValue(); if (row instanceof Map) { itemValue = ((Map) row).get(pProperty); } else { try { itemValue = PropertyUtils.getProperty(row, pProperty); } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug(":" + pItem.getClass().getName() + "?:" + pProperty); } } //end try-catch } //end else return itemValue; }