@Test public void testBuildCreateMessage() throws ParseException { final SystemCodes sc = new SystemCodes("category","key","value"); final String expected = "<p class='add-message'>Added new System Codes with Value:<span class='primary-field'>value</span> " + "with the following: Key=<span class='field-value'>KEY</span> and Category=<span class='field-value'>CATEGORY</span> </p>"; Assert.assertEquals(expected, CrudUtil.buildCreateMessage(sc)); sc.setCreateDate(new Date()); final String cDate = DateUtil.dateToString(sc.getCreateDate(), "EEE, dd MMM yyyy HH:mm:ss z"); final String expected2 = "<p class='add-message'>Added new System Codes with Value:<span class='primary-field'>value</span> " + "with the following: " + "Key=<span class='field-value'>KEY</span> and Category=<span class='field-value'>CATEGORY</span> </p>"; Assert.assertEquals(expected2, CrudUtil.buildCreateMessage(sc)); final Date date = DateUtil.stringToDate("03/12/2013", "MM/dd/yyyy"); final SystemCodes sc3 = new SystemCodes("category","key","value"); sc3.setCreateDate(date); final String expected3 = "<p class='add-message'>Added new System Codes with Value:<span class='primary-field'>value</span> " + "with the following: " + "Key=<span class='field-value'>KEY</span> and Category=<span class='field-value'>CATEGORY</span> </p>"; Assert.assertEquals(expected3, CrudUtil.buildCreateMessage(sc3)); }
public static String buildCreateMessage(final BaseEntity obj) { final StringBuilder message = new StringBuilder(); if (obj.getClass().isAnnotationPresent(Auditable.class)) { final AuditableField pf = CacheUtil.getPrimaryField(obj); message.append("<p class='add-message'>Added new "); message.append(buildPrimaryField(pf, obj)).append( " with the following: "); final List<AuditableField> auditFields = CacheUtil .getAuditable(obj); int count = 0; for (final AuditableField property : auditFields) { Object ret = retrieveNullableObjectValue(obj, property.getFieldName()); ret = normalizeValue(ret); if (ret.toString().trim().length() > 0 && !pf.getFieldName().equals(property.getFieldName())) { if (count > 0) { message.append("and "); } message.append(property.getTitle()) .append("=<span class='field-value'>") .append(ret.toString()).append("</span> "); count++; } } message.append("</p>"); } return message.toString(); }
CrudUtil { public static String buildCreateMessage(final BaseEntity obj) { final StringBuilder message = new StringBuilder(); if (obj.getClass().isAnnotationPresent(Auditable.class)) { final AuditableField pf = CacheUtil.getPrimaryField(obj); message.append("<p class='add-message'>Added new "); message.append(buildPrimaryField(pf, obj)).append( " with the following: "); final List<AuditableField> auditFields = CacheUtil .getAuditable(obj); int count = 0; for (final AuditableField property : auditFields) { Object ret = retrieveNullableObjectValue(obj, property.getFieldName()); ret = normalizeValue(ret); if (ret.toString().trim().length() > 0 && !pf.getFieldName().equals(property.getFieldName())) { if (count > 0) { message.append("and "); } message.append(property.getTitle()) .append("=<span class='field-value'>") .append(ret.toString()).append("</span> "); count++; } } message.append("</p>"); } return message.toString(); } }
CrudUtil { public static String buildCreateMessage(final BaseEntity obj) { final StringBuilder message = new StringBuilder(); if (obj.getClass().isAnnotationPresent(Auditable.class)) { final AuditableField pf = CacheUtil.getPrimaryField(obj); message.append("<p class='add-message'>Added new "); message.append(buildPrimaryField(pf, obj)).append( " with the following: "); final List<AuditableField> auditFields = CacheUtil .getAuditable(obj); int count = 0; for (final AuditableField property : auditFields) { Object ret = retrieveNullableObjectValue(obj, property.getFieldName()); ret = normalizeValue(ret); if (ret.toString().trim().length() > 0 && !pf.getFieldName().equals(property.getFieldName())) { if (count > 0) { message.append("and "); } message.append(property.getTitle()) .append("=<span class='field-value'>") .append(ret.toString()).append("</span> "); count++; } } message.append("</p>"); } return message.toString(); } private  CrudUtil(); }
CrudUtil { public static String buildCreateMessage(final BaseEntity obj) { final StringBuilder message = new StringBuilder(); if (obj.getClass().isAnnotationPresent(Auditable.class)) { final AuditableField pf = CacheUtil.getPrimaryField(obj); message.append("<p class='add-message'>Added new "); message.append(buildPrimaryField(pf, obj)).append( " with the following: "); final List<AuditableField> auditFields = CacheUtil .getAuditable(obj); int count = 0; for (final AuditableField property : auditFields) { Object ret = retrieveNullableObjectValue(obj, property.getFieldName()); ret = normalizeValue(ret); if (ret.toString().trim().length() > 0 && !pf.getFieldName().equals(property.getFieldName())) { if (count > 0) { message.append("and "); } message.append(property.getTitle()) .append("=<span class='field-value'>") .append(ret.toString()).append("</span> "); count++; } } message.append("</p>"); } return message.toString(); } 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 { public static String buildCreateMessage(final BaseEntity obj) { final StringBuilder message = new StringBuilder(); if (obj.getClass().isAnnotationPresent(Auditable.class)) { final AuditableField pf = CacheUtil.getPrimaryField(obj); message.append("<p class='add-message'>Added new "); message.append(buildPrimaryField(pf, obj)).append( " with the following: "); final List<AuditableField> auditFields = CacheUtil .getAuditable(obj); int count = 0; for (final AuditableField property : auditFields) { Object ret = retrieveNullableObjectValue(obj, property.getFieldName()); ret = normalizeValue(ret); if (ret.toString().trim().length() > 0 && !pf.getFieldName().equals(property.getFieldName())) { if (count > 0) { message.append("and "); } message.append(property.getTitle()) .append("=<span class='field-value'>") .append(ret.toString()).append("</span> "); count++; } } message.append("</p>"); } return message.toString(); } 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);  }