/** * This method checks whether the instance of the class was initialized properly. * * @throws OPMConfigurationException if the instance was not initialized properly(widgetIds is * null or contains null/empty element; securityService or userService is null; userSessionKey * is null/empty). */ @PostConstruct protected void checkInit() { Helper.checkState(widgetIds == null, "'widgetIds' can't be null."); for (String widgetId : widgetIds) { Helper.checkState( WebHelper.isNullOrEmpty(widgetId), "'widgetIds' can't contain null/empty element."); } Helper.checkState(securityService == null, "'securityService' can't be null."); Helper.checkState(userService == null, "'userService' can't be null."); Helper.checkState( WebHelper.isNullOrEmpty(userSessionKey), "'userSessionKey' can't be null/empty."); }
/** * Audit the entity * * @param request the http servlet request * @param auditService the audit service * @param user the current user * @param action the action name * @param newEntity the new entity to audit * @param oldEntity the old entity to audit * @throws OPMException if any error occurs */ public static void auditEntity( HttpServletRequest request, AuditService auditService, User user, String action, IdentifiableEntity oldEntity, IdentifiableEntity newEntity) throws OPMException { List<Object[]> objs = new ArrayList<Object[]>(); List<String> fields = getFields(newEntity); for (String field : fields) { Object oldValue = getField(oldEntity, field); if (oldValue == null) { oldValue = "null"; } Object newValue = getField(newEntity, field); if (newValue == null) { newValue = "null"; } boolean equal = oldValue.equals(newValue); if (oldValue.toString().length() > 128) { oldValue = oldValue.toString().substring(0, 128); } if (newValue.toString().length() > 128) { newValue = newValue.toString().substring(0, 128); } if (!equal) { Object[] ab = new Object[] { newEntity.getId(), newEntity.getClass().getName(), field, oldValue, newValue }; objs.add(ab); } } WebHelper.audit(request, auditService, user, action, objs); }