private static Optional<Date> findLastChangeOfEmployeeStatusInHistory(final EmployeeDO employee) { final Predicate<HistoryEntry> hasStatusChangeHistoryEntries = historyEntry -> ((HistoryEntry<?>) historyEntry) .getDiffEntries() .stream() .anyMatch( diffEntry -> diffEntry.getPropertyName().startsWith("status") ); return HistoryBaseDaoAdapter .getHistoryEntries(employee) .stream() .filter(hasStatusChangeHistoryEntries) .map(HistoryEntry::getModifiedAt) .findFirst(); // the history entries are already sorted by date } }
public SimpleHistoryEntry(final UserGroupCache userGroupCache, final HistoryEntry entry) { this.timestamp = entry.getModifiedAt(); final Integer userId = NumberHelper.parseInteger(entry.getUserName()); if (userId != null) { this.user = userGroupCache.getUser(userId); } // entry.getClassName(); // entry.getComment(); this.entryType = entry.getEntityOpType(); // entry.getEntityId(); }
@SuppressWarnings("rawtypes") protected void assertHistoryEntry(final HistoryEntry entry, final Integer entityId, final PFUserDO user, final EntityOpType type, final String propertyName, final Class<?> classType, final Object oldValue, final Object newValue) { assertEquals(user.getId().toString(), entry.getUserName()); // assertEquals(AddressDO.class.getSimpleName(), entry.getClassName()); assertEquals(null, entry.getUserComment()); assertEquals(type, entry.getEntityOpType()); assertEquals(entityId, entry.getEntityId()); if (propertyName != null) { fail("TODO HISTORY History not yet implemented"); } }
final Class<?> type = xstreamSavingConverter.getClassFromHistoryName(historyEntry.getEntityName()); final Object o = type != null ? session.get(type, historyEntry.getEntityId()) : null; if (o == null) { log.warn("A corrupted history entry found (entity of class '" + historyEntry.getEntityName() + "' with id " + historyEntry.getEntityId() + " not found: " + historyEntry
/** * <b>Beachte Sicherheitshinweis:</b> Beim Überladen bitte dynamische Inhalte immer mit escapeHtml ausgeben (Vorsicht: * Cross site scripting). * * @see de.micromata.hibernate.history.web.HistoryFormatter#formatUser(org.hibernate.Session, java.util.Locale, * de.micromata.hibernate.history.HistoryEntry) */ @Override public String formatUser(Session session, final Locale locale, Object changed, HistoryEntry historyEntry, PropertyDelta delta) { return escapeHtml(historyEntry.getUserName()); }
/** * @see de.micromata.hibernate.history.web.HistoryFormatter#formatAction(org.hibernate.Session, java.util.Locale, * de.micromata.hibernate.history.HistoryEntry) */ @Override public String formatAction(Session session, final Locale locale, Object changed, HistoryEntry historyEntry, PropertyDelta delta) { switch (historyEntry.getEntityOpType()) { case MarkDeleted: case Deleted: return getDeletedAction(locale); case UmarkDeleted: case Update: return getUpdatedAction(locale); case Insert: return getInsertedAction(locale); } return null; }
/** * @see de.micromata.hibernate.history.web.HistoryFormatter#formatTimestamp(org.hibernate.Session, java.util.Locale, * de.micromata.hibernate.history.HistoryEntry) */ @Override public String formatTimestamp(Session session, final Locale locale, Object changed, HistoryEntry historyEntry, PropertyDelta delta) { return sdf.format(historyEntry.getModifiedAt()); }
/** * (don't forget escapeHtml!) * * @see de.micromata.hibernate.history.web.HistoryFormatter#formatNewValue(org.hibernate.Session, java.util.Locale, * java.lang.Object, de.micromata.hibernate.history.HistoryEntry, * de.micromata.hibernate.history.delta.PropertyDelta) */ @Override public String formatNewValue(Session session, final Locale locale, Object changed, HistoryEntry historyEntry, PropertyDelta delta) { return asString(session, locale, historyEntry.getEntityName(), delta == null ? "" : delta.getPropertyName(), delta == null ? "" : delta.getNewValue()); }
} else if (obj instanceof HistoryEntry) { ((HistoryEntry) obj).setPk(null); id = session.save(obj); } else if (obj instanceof PropertyDelta) {
@Override public String formatUser(final Session session, final Locale locale, final Object changed, final HistoryEntry historyEntry, final PropertyDelta delta) { final String[] users = StringUtils.split(historyEntry.getUserName(), ","); if (users != null && users.length > 0) { try { final PFUserDO user = session.load(PFUserDO.class, Integer.valueOf(users[0])); return "<img src=\"images/user.gif\" valign=\"middle\" width=\"20\" height=\"20\" border=\"0\" /> " + escapeHtml(user.getFullname()); } catch (final HibernateException ex) { log.warn("Can't load history-user " + historyEntry.getUserName()); return "unknown"; } } return escapeHtml(historyEntry.getUserName()); }
public static List<? extends HistoryEntry> getHistoryEntries(BaseDO<?> ob) { long begin = System.currentTimeMillis(); HistoryService histservice = HistoryServiceManager.get().getHistoryService(); PfEmgrFactory emf = ApplicationContextProvider.getApplicationContext().getBean(PfEmgrFactory.class); List<? extends HistoryEntry> ret = emf.runInTrans((emgr) -> { return histservice.getHistoryEntries(emgr, ob); }); List<? extends HistoryEntry> nret = ret.stream() .sorted((e1, e2) -> e2.getModifiedAt().compareTo(e1.getModifiedAt())).collect(Collectors.toList()); long end = System.currentTimeMillis(); log.info("HistoryBaseDaoAdapter.getHistoryEntries took: " + (end - begin) + " ms."); return nret; }
/** * (don't forget escapeHtml!) * * @see de.micromata.hibernate.history.web.HistoryFormatter#formatOldValue(org.hibernate.Session, java.util.Locale, * java.lang.Object, de.micromata.hibernate.history.HistoryEntry, * de.micromata.hibernate.history.delta.PropertyDelta) */ @Override public String formatOldValue(Session session, final Locale locale, Object changed, HistoryEntry historyEntry, PropertyDelta delta) { return asString(session, locale, historyEntry.getEntityName(), delta == null ? "" : delta.getPropertyName(), delta == null ? "" : delta.getOldValue()); }
public DisplayHistoryEntry(final UserGroupCache userGroupCache, final HistoryEntry entry) { this.timestamp = entry.getModifiedAt(); final Integer userId = NumberHelper.parseInteger(entry.getUserName()); if (userId != null) { this.user = userGroupCache.getUser(userId); } // entry.getClassName(); // entry.getComment(); this.entryType = entry.getEntityOpType(); // entry.getEntityId(); }
public List<DisplayHistoryEntry> convert(final HistoryEntry<?> entry, final Session session) { if (entry.getDiffEntries().isEmpty() == true) { final DisplayHistoryEntry se = new DisplayHistoryEntry(getUserGroupCache(), entry); return Collections.singletonList(se); } List<DisplayHistoryEntry> result = new ArrayList<>(); for (DiffEntry prop : entry.getDiffEntries()) { DisplayHistoryEntry se = new DisplayHistoryEntry(getUserGroupCache(), entry, prop, session); result.add(se); } return result; }
public static List<SimpleHistoryEntry> getSimpleHistoryEntries(final BaseDO<?> ob, UserGroupCache userGroupCache) { long begin = System.currentTimeMillis(); List<SimpleHistoryEntry> ret = new ArrayList<>(); List<? extends HistoryEntry> hel = getHistoryEntries(ob); for (HistoryEntry he : hel) { List<DiffEntry> deltas = he.getDiffEntries(); if (deltas.isEmpty() == true) { SimpleHistoryEntry se = new SimpleHistoryEntry(userGroupCache, he); ret.add(se); } else { for (DiffEntry de : deltas) { final SimpleHistoryEntry se = new SimpleHistoryEntry(userGroupCache, he, diffEntryToPropertyDelta(de)); ret.add(se); } } } long end = System.currentTimeMillis(); log.info("HistoryBaseDaoAdapter.getSimpleHistoryEntries took: " + (end - begin) + " ms."); return ret; }
@Override public List<DisplayHistoryEntry> convert(final HistoryEntry<?> entry, final Session session) if (entry.getDiffEntries().isEmpty() == true) { final DisplayHistoryEntry se = new DisplayHistoryEntry(getUserGroupCache(), entry); return Collections.singletonList(se); for (DiffEntry prop : entry.getDiffEntries()) { DisplayHistoryEntry se = new DisplayHistoryEntry(getUserGroupCache(), entry, prop, session)