@Override @Transactional(propagation = Propagation.REQUIRED) public void logChange(LogEntry.ActionType action, String username, AbstractDomainObject value) { LogEntry entry = new LogEntry(); entry.setAction(action); entry.setUsername(username); entry.setClazz(value.getClass()); entry.setIdentifier(value.getId()); entry.setValue(value.toString()); entry.setUiName(value.getUIName()); entityManager.persist(entry); }
@Override @Transactional(propagation = Propagation.REQUIRED) public void logRandomize( LogEntry.ActionType action, String username, Trial trial, TrialSubject trialSubject) { LogEntry entry = new LogEntry(); entry.setAction(action); entry.setUsername(username); entry.setClazz(trial.getClass()); entry.setIdentifier(trial.getId()); entry.setValue(trialSubject.toString()); entry.setUiName(trialSubject.getUIName()); entityManager.persist(entry); }
@Override @Transactional(propagation = Propagation.REQUIRED) public void logTrialChange( LogEntry.ActionType action, String username, Trial oldTrial, Trial changedTrial) { LogEntry entry = new LogEntry(); entry.setAction(action); entry.setUsername(username); entry.setClazz(Trial.class); entry.setIdentifier(changedTrial.getId()); StringBuilder sb = new StringBuilder(); if (!oldTrial.getName().equals(changedTrial.getName())) { sb.append("Name: ") .append(oldTrial.getName()) .append(" -> ") .append(changedTrial.getName()) .append(" | "); } if (!oldTrial.getAbbreviation().equals(changedTrial.getAbbreviation())) { sb.append("Abbreviation: ") .append(oldTrial.getAbbreviation()) .append(" -> ") .append(changedTrial.getAbbreviation()) .append(" | "); } if (!oldTrial.getDescription().equals(changedTrial.getDescription())) { sb.append("Description: ") .append(oldTrial.getDescription()) .append(" -> ") .append(changedTrial.getDescription()) .append(" | "); } if (!oldTrial.getStartDate().equals(changedTrial.getStartDate())) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sb.append("Start-Date: ") .append(sdf.format(oldTrial.getStartDate().getTime())) .append(" -> ") .append(sdf.format(changedTrial.getStartDate().getTime())) .append(" | "); } if (!oldTrial.getEndDate().equals(changedTrial.getEndDate())) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sb.append("End-Date: ") .append(sdf.format(oldTrial.getEndDate().getTime())) .append(" -> ") .append(sdf.format(changedTrial.getEndDate().getTime())) .append(" | "); } if (!oldTrial.getLeadingSite().equals(changedTrial.getLeadingSite())) { sb.append("Leading Site: ") .append(oldTrial.getLeadingSite().getName()) .append(" -> ") .append(changedTrial.getLeadingSite().getName()) .append(" | "); } if (!oldTrial.getSponsorInvestigator().equals(changedTrial.getSponsorInvestigator())) { sb.append("Sponsor investigator: ") .append(oldTrial.getSponsorInvestigator().getUIName()) .append(" -> ") .append(changedTrial.getSponsorInvestigator().getUIName()) .append(" | "); } if (!(oldTrial.getStatus() == changedTrial.getStatus())) { sb.append("Status: ") .append(oldTrial.getStatus()) .append(" -> ") .append(changedTrial.getStatus()); } if (sb.length() == 0) { sb.append(changedTrial.getAbbreviation()); } entry.setUiName(sb.toString()); entry.setValue(sb.toString()); entityManager.persist(entry); }