@SuppressWarnings("rawtypes") @Test public void testRetrieveObjectValueArray1() { final UserCriteria user = new UserCriteria(); user.setFirstName("Test"); user.setEmailAddress("admin@ideyatech.com"); final List<SystemCodes> codes = new ArrayList<SystemCodes>(); codes.add(new SystemCodes("CATEGORY", "STRING_1", "VALUE_1")); codes.add(new SystemCodes("CATEGORY", "STRING_2", "VALUE_2")); codes.add(new SystemCodes("CATEGORY", "STRING_3", "VALUE_3")); user.setFavorites(codes); final List keysResult = (List) CrudUtil.retrieveObjectValue(user, "favorites.key"); Assert.assertEquals(3, keysResult.size()); Assert.assertEquals("STRING_1", keysResult.get(0)); Assert.assertEquals("STRING_2", keysResult.get(1)); Assert.assertEquals("STRING_3", keysResult.get(2)); final List valuesResult = (List) CrudUtil.retrieveObjectValue(user, "favorites.value"); Assert.assertEquals(3, keysResult.size()); Assert.assertEquals("VALUE_1", valuesResult.get(0)); Assert.assertEquals("VALUE_2", valuesResult.get(1)); Assert.assertEquals("VALUE_3", valuesResult.get(2)); }
@SuppressWarnings("rawtypes") public static Object retrieveObjectValue(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { Object ivalue = null; if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; ivalue = map.get(props[0]); } else { Method method; if (props[0].startsWith("get")) { method = obj.getClass().getMethod(props[0]); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); } ivalue = method.invoke(obj); } if (ivalue == null) { return null; } if (Collection.class.isAssignableFrom(ivalue.getClass())) { final Iterator iter = ((Collection) ivalue).iterator(); final List<Object> ret = new ArrayList<Object>(); final String prop = property .substring(props[0].length() + 1); while (iter.hasNext()) { final Object lvalue = iter.next(); if (lvalue != null) { ret.add(retrieveObjectValue(lvalue, prop)); } } return ret; } return retrieveObjectValue(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; return map.get(property); } else { Method method; if (property.startsWith("get")) { method = obj.getClass().getMethod(property); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); } return method.invoke(obj); } } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } }
CrudUtil { @SuppressWarnings("rawtypes") public static Object retrieveObjectValue(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { Object ivalue = null; if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; ivalue = map.get(props[0]); } else { Method method; if (props[0].startsWith("get")) { method = obj.getClass().getMethod(props[0]); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); } ivalue = method.invoke(obj); } if (ivalue == null) { return null; } if (Collection.class.isAssignableFrom(ivalue.getClass())) { final Iterator iter = ((Collection) ivalue).iterator(); final List<Object> ret = new ArrayList<Object>(); final String prop = property .substring(props[0].length() + 1); while (iter.hasNext()) { final Object lvalue = iter.next(); if (lvalue != null) { ret.add(retrieveObjectValue(lvalue, prop)); } } return ret; } return retrieveObjectValue(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; return map.get(property); } else { Method method; if (property.startsWith("get")) { method = obj.getClass().getMethod(property); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); } return method.invoke(obj); } } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } }
CrudUtil { @SuppressWarnings("rawtypes") public static Object retrieveObjectValue(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { Object ivalue = null; if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; ivalue = map.get(props[0]); } else { Method method; if (props[0].startsWith("get")) { method = obj.getClass().getMethod(props[0]); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); } ivalue = method.invoke(obj); } if (ivalue == null) { return null; } if (Collection.class.isAssignableFrom(ivalue.getClass())) { final Iterator iter = ((Collection) ivalue).iterator(); final List<Object> ret = new ArrayList<Object>(); final String prop = property .substring(props[0].length() + 1); while (iter.hasNext()) { final Object lvalue = iter.next(); if (lvalue != null) { ret.add(retrieveObjectValue(lvalue, prop)); } } return ret; } return retrieveObjectValue(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; return map.get(property); } else { Method method; if (property.startsWith("get")) { method = obj.getClass().getMethod(property); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); } return method.invoke(obj); } } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } private  CrudUtil(); }
CrudUtil { @SuppressWarnings("rawtypes") public static Object retrieveObjectValue(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { Object ivalue = null; if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; ivalue = map.get(props[0]); } else { Method method; if (props[0].startsWith("get")) { method = obj.getClass().getMethod(props[0]); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); } ivalue = method.invoke(obj); } if (ivalue == null) { return null; } if (Collection.class.isAssignableFrom(ivalue.getClass())) { final Iterator iter = ((Collection) ivalue).iterator(); final List<Object> ret = new ArrayList<Object>(); final String prop = property .substring(props[0].length() + 1); while (iter.hasNext()) { final Object lvalue = iter.next(); if (lvalue != null) { ret.add(retrieveObjectValue(lvalue, prop)); } } return ret; } return retrieveObjectValue(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; return map.get(property); } else { Method method; if (property.startsWith("get")) { method = obj.getClass().getMethod(property); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); } return method.invoke(obj); } } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } private  CrudUtil(); static String buildCreateMessage(final BaseEntity obj); static List<String> getUpdatedFields(final BaseEntity oldObject,
			final BaseEntity newObject); static String convertAuditableFieldsToJson(BaseEntity obj); @SuppressWarnings({ "rawtypes", "unchecked" }) static String buildUpdateMessage(final BaseEntity oldObject,
			final BaseEntity newObject); static String buildDeleteMessage(final BaseEntity obj); static Map<String, Object> buildMapValues(final BaseEntity object); @SuppressWarnings("rawtypes") static Map<String, Object> buildMapValues(final BaseEntity object,
			final List<String> fields); static String buildURLParameters(final BaseEntity object); @SuppressWarnings("rawtypes") static String buildJpaQueryString(final BaseEntity example,
			final boolean exactMatch); @SuppressWarnings("rawtypes") static Object retrieveObjectValue(final Object obj,
			final String property); static Object retrieveNullableObjectValue(final Object obj,
			final String property); static Class<?> retrieveObjectType(final Object obj,
			final String property); static Boolean evaluateExpression(final Object obj,
			final String expression); @SuppressWarnings("unchecked") static String replaceSQLParameters(String sql, final Object obj); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz,
			final boolean includeParent); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz,
			final boolean includeParent); static List<MessageResponse> convertErrorMessage(
			final BindingResult bindingResult, final Locale locale,
			final MessageSource messageSource); static List<MessageResponse> buildSuccessMessage(
			final BaseEntity object, final String code, final Locale locale,
			final MessageSource messageSource); static boolean isCollection(final Object ob); static BaseEntity clone(final BaseEntity source); }
CrudUtil { @SuppressWarnings("rawtypes") public static Object retrieveObjectValue(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { Object ivalue = null; if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; ivalue = map.get(props[0]); } else { Method method; if (props[0].startsWith("get")) { method = obj.getClass().getMethod(props[0]); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); } ivalue = method.invoke(obj); } if (ivalue == null) { return null; } if (Collection.class.isAssignableFrom(ivalue.getClass())) { final Iterator iter = ((Collection) ivalue).iterator(); final List<Object> ret = new ArrayList<Object>(); final String prop = property .substring(props[0].length() + 1); while (iter.hasNext()) { final Object lvalue = iter.next(); if (lvalue != null) { ret.add(retrieveObjectValue(lvalue, prop)); } } return ret; } return retrieveObjectValue(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { if (Map.class.isAssignableFrom(obj.getClass())) { final Map map = (Map) obj; return map.get(property); } else { Method method; if (property.startsWith("get")) { method = obj.getClass().getMethod(property); } else { method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); } return method.invoke(obj); } } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } private  CrudUtil(); static String buildCreateMessage(final BaseEntity obj); static List<String> getUpdatedFields(final BaseEntity oldObject,
			final BaseEntity newObject); static String convertAuditableFieldsToJson(BaseEntity obj); @SuppressWarnings({ "rawtypes", "unchecked" }) static String buildUpdateMessage(final BaseEntity oldObject,
			final BaseEntity newObject); static String buildDeleteMessage(final BaseEntity obj); static Map<String, Object> buildMapValues(final BaseEntity object); @SuppressWarnings("rawtypes") static Map<String, Object> buildMapValues(final BaseEntity object,
			final List<String> fields); static String buildURLParameters(final BaseEntity object); @SuppressWarnings("rawtypes") static String buildJpaQueryString(final BaseEntity example,
			final boolean exactMatch); @SuppressWarnings("rawtypes") static Object retrieveObjectValue(final Object obj,
			final String property); static Object retrieveNullableObjectValue(final Object obj,
			final String property); static Class<?> retrieveObjectType(final Object obj,
			final String property); static Boolean evaluateExpression(final Object obj,
			final String expression); @SuppressWarnings("unchecked") static String replaceSQLParameters(String sql, final Object obj); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz,
			final boolean includeParent); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz,
			final boolean includeParent); static List<MessageResponse> convertErrorMessage(
			final BindingResult bindingResult, final Locale locale,
			final MessageSource messageSource); static List<MessageResponse> buildSuccessMessage(
			final BaseEntity object, final String code, final Locale locale,
			final MessageSource messageSource); static boolean isCollection(final Object ob); static BaseEntity clone(final BaseEntity source);  }