@Test public void testlistAllConfigPropertyAudits() throws Exception { List<ConfigPropertyAudit> configPropertyAuditList = new ArrayList<>(); ConfigPropertyAudit auditItem1 = new ConfigPropertyAudit(); auditItem1.setApplication("application"); auditItem1.setCfkey("logging.esHost"); auditItem1.setLabel("latest"); auditItem1.setOldvalue("old"); auditItem1.setNewvalue("new"); auditItem1.setModifiedDate("01/01/2013 01:01:01"); configPropertyAuditList.add(auditItem1); ConfigPropertyAudit auditItem2 = new ConfigPropertyAudit(); auditItem2.setApplication("application"); auditItem2.setCfkey("logging.esHost"); auditItem2.setLabel("latest"); auditItem2.setOldvalue("new"); auditItem2.setNewvalue("newest"); auditItem2.setModifiedDate("02/02/2013 01:01:01"); configPropertyAuditList.add(auditItem2); when(configPropertyAuditRepository.findAllByOrderByModifiedDateDescModifiedByAsc()) .thenReturn(configPropertyAuditList); assertTrue(configPropertyService.listAllConfigPropertyAudits("01/01/2012 01:01:01").getConfigPropertyAudit() .size() > 0); }
@Override public ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp) throws Exception { if (StringUtils.isEmpty(timestamp)) { LocalDateTime now = LocalDateTime.now(); timestamp = now.minusMonths(1).format(DateTimeFormatter.ofPattern(DATE_FORMAT)); } List<ConfigPropertyAudit> allStoredAudits = configPropertyAuditRepository .findAllByOrderByModifiedDateDescModifiedByAsc(); Comparator<ConfigPropertyAudit> comp = ((m2, m1) -> LocalDateTime .parse(m1.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)).compareTo( LocalDateTime.parse(m2.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)))); Collections.sort(allStoredAudits, comp); ConfigPropertyAuditItem previousAuditItem = new ConfigPropertyAuditItem(); ConfigPropertyAuditItem currentAuditItem = new ConfigPropertyAuditItem(); List<ConfigPropertyDataChange> dataChangeList = new ArrayList<ConfigPropertyDataChange>(); List<ConfigPropertyAuditItem> auditItemList = new ArrayList<>(); for (ConfigPropertyAudit storedAudit : allStoredAudits) { if (LocalDateTime.parse(storedAudit.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)) .isBefore(LocalDateTime.parse(timestamp, DateTimeFormatter.ofPattern(DATE_FORMAT)))) { break; } if (!(storedAudit.getModifiedDate().equals(previousAuditItem.getAuditTimeStamp()) && storedAudit.getModifiedBy().equals(previousAuditItem.getModifiedBy()))) { if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); currentAuditItem = new ConfigPropertyAuditItem(); dataChangeList = new ArrayList<ConfigPropertyDataChange>(); } } currentAuditItem.setConfigPropertyChangeList(dataChangeList); currentAuditItem.setAuditTimeStamp(storedAudit.getModifiedDate()); currentAuditItem.setModifiedBy(storedAudit.getModifiedBy()); currentAuditItem.setUserMessage(storedAudit.getUserMessage()); currentAuditItem.setSystemMessage(storedAudit.getSystemMessage()); ConfigPropertyDataChange dataChange = new ConfigPropertyDataChange(); dataChange.setConfigKey(storedAudit.getCfkey()); dataChange.setApplication(storedAudit.getApplication()); dataChange.setOldConfigValue(storedAudit.getOldvalue()); dataChange.setNewConfigValue(storedAudit.getNewvalue()); dataChangeList.add(dataChange); previousAuditItem = currentAuditItem; } if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); } ConfigPropertyAuditTrail trail = new ConfigPropertyAuditTrail(); trail.setConfigPropertyAudit(auditItemList); return trail; }
ConfigPropertyServiceImpl implements ConfigPropertyService { @Override public ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp) throws Exception { if (StringUtils.isEmpty(timestamp)) { LocalDateTime now = LocalDateTime.now(); timestamp = now.minusMonths(1).format(DateTimeFormatter.ofPattern(DATE_FORMAT)); } List<ConfigPropertyAudit> allStoredAudits = configPropertyAuditRepository .findAllByOrderByModifiedDateDescModifiedByAsc(); Comparator<ConfigPropertyAudit> comp = ((m2, m1) -> LocalDateTime .parse(m1.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)).compareTo( LocalDateTime.parse(m2.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)))); Collections.sort(allStoredAudits, comp); ConfigPropertyAuditItem previousAuditItem = new ConfigPropertyAuditItem(); ConfigPropertyAuditItem currentAuditItem = new ConfigPropertyAuditItem(); List<ConfigPropertyDataChange> dataChangeList = new ArrayList<ConfigPropertyDataChange>(); List<ConfigPropertyAuditItem> auditItemList = new ArrayList<>(); for (ConfigPropertyAudit storedAudit : allStoredAudits) { if (LocalDateTime.parse(storedAudit.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)) .isBefore(LocalDateTime.parse(timestamp, DateTimeFormatter.ofPattern(DATE_FORMAT)))) { break; } if (!(storedAudit.getModifiedDate().equals(previousAuditItem.getAuditTimeStamp()) && storedAudit.getModifiedBy().equals(previousAuditItem.getModifiedBy()))) { if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); currentAuditItem = new ConfigPropertyAuditItem(); dataChangeList = new ArrayList<ConfigPropertyDataChange>(); } } currentAuditItem.setConfigPropertyChangeList(dataChangeList); currentAuditItem.setAuditTimeStamp(storedAudit.getModifiedDate()); currentAuditItem.setModifiedBy(storedAudit.getModifiedBy()); currentAuditItem.setUserMessage(storedAudit.getUserMessage()); currentAuditItem.setSystemMessage(storedAudit.getSystemMessage()); ConfigPropertyDataChange dataChange = new ConfigPropertyDataChange(); dataChange.setConfigKey(storedAudit.getCfkey()); dataChange.setApplication(storedAudit.getApplication()); dataChange.setOldConfigValue(storedAudit.getOldvalue()); dataChange.setNewConfigValue(storedAudit.getNewvalue()); dataChangeList.add(dataChange); previousAuditItem = currentAuditItem; } if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); } ConfigPropertyAuditTrail trail = new ConfigPropertyAuditTrail(); trail.setConfigPropertyAudit(auditItemList); return trail; } }
ConfigPropertyServiceImpl implements ConfigPropertyService { @Override public ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp) throws Exception { if (StringUtils.isEmpty(timestamp)) { LocalDateTime now = LocalDateTime.now(); timestamp = now.minusMonths(1).format(DateTimeFormatter.ofPattern(DATE_FORMAT)); } List<ConfigPropertyAudit> allStoredAudits = configPropertyAuditRepository .findAllByOrderByModifiedDateDescModifiedByAsc(); Comparator<ConfigPropertyAudit> comp = ((m2, m1) -> LocalDateTime .parse(m1.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)).compareTo( LocalDateTime.parse(m2.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)))); Collections.sort(allStoredAudits, comp); ConfigPropertyAuditItem previousAuditItem = new ConfigPropertyAuditItem(); ConfigPropertyAuditItem currentAuditItem = new ConfigPropertyAuditItem(); List<ConfigPropertyDataChange> dataChangeList = new ArrayList<ConfigPropertyDataChange>(); List<ConfigPropertyAuditItem> auditItemList = new ArrayList<>(); for (ConfigPropertyAudit storedAudit : allStoredAudits) { if (LocalDateTime.parse(storedAudit.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)) .isBefore(LocalDateTime.parse(timestamp, DateTimeFormatter.ofPattern(DATE_FORMAT)))) { break; } if (!(storedAudit.getModifiedDate().equals(previousAuditItem.getAuditTimeStamp()) && storedAudit.getModifiedBy().equals(previousAuditItem.getModifiedBy()))) { if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); currentAuditItem = new ConfigPropertyAuditItem(); dataChangeList = new ArrayList<ConfigPropertyDataChange>(); } } currentAuditItem.setConfigPropertyChangeList(dataChangeList); currentAuditItem.setAuditTimeStamp(storedAudit.getModifiedDate()); currentAuditItem.setModifiedBy(storedAudit.getModifiedBy()); currentAuditItem.setUserMessage(storedAudit.getUserMessage()); currentAuditItem.setSystemMessage(storedAudit.getSystemMessage()); ConfigPropertyDataChange dataChange = new ConfigPropertyDataChange(); dataChange.setConfigKey(storedAudit.getCfkey()); dataChange.setApplication(storedAudit.getApplication()); dataChange.setOldConfigValue(storedAudit.getOldvalue()); dataChange.setNewConfigValue(storedAudit.getNewvalue()); dataChangeList.add(dataChange); previousAuditItem = currentAuditItem; } if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); } ConfigPropertyAuditTrail trail = new ConfigPropertyAuditTrail(); trail.setConfigPropertyAudit(auditItemList); return trail; }  }
ConfigPropertyServiceImpl implements ConfigPropertyService { @Override public ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp) throws Exception { if (StringUtils.isEmpty(timestamp)) { LocalDateTime now = LocalDateTime.now(); timestamp = now.minusMonths(1).format(DateTimeFormatter.ofPattern(DATE_FORMAT)); } List<ConfigPropertyAudit> allStoredAudits = configPropertyAuditRepository .findAllByOrderByModifiedDateDescModifiedByAsc(); Comparator<ConfigPropertyAudit> comp = ((m2, m1) -> LocalDateTime .parse(m1.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)).compareTo( LocalDateTime.parse(m2.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)))); Collections.sort(allStoredAudits, comp); ConfigPropertyAuditItem previousAuditItem = new ConfigPropertyAuditItem(); ConfigPropertyAuditItem currentAuditItem = new ConfigPropertyAuditItem(); List<ConfigPropertyDataChange> dataChangeList = new ArrayList<ConfigPropertyDataChange>(); List<ConfigPropertyAuditItem> auditItemList = new ArrayList<>(); for (ConfigPropertyAudit storedAudit : allStoredAudits) { if (LocalDateTime.parse(storedAudit.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)) .isBefore(LocalDateTime.parse(timestamp, DateTimeFormatter.ofPattern(DATE_FORMAT)))) { break; } if (!(storedAudit.getModifiedDate().equals(previousAuditItem.getAuditTimeStamp()) && storedAudit.getModifiedBy().equals(previousAuditItem.getModifiedBy()))) { if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); currentAuditItem = new ConfigPropertyAuditItem(); dataChangeList = new ArrayList<ConfigPropertyDataChange>(); } } currentAuditItem.setConfigPropertyChangeList(dataChangeList); currentAuditItem.setAuditTimeStamp(storedAudit.getModifiedDate()); currentAuditItem.setModifiedBy(storedAudit.getModifiedBy()); currentAuditItem.setUserMessage(storedAudit.getUserMessage()); currentAuditItem.setSystemMessage(storedAudit.getSystemMessage()); ConfigPropertyDataChange dataChange = new ConfigPropertyDataChange(); dataChange.setConfigKey(storedAudit.getCfkey()); dataChange.setApplication(storedAudit.getApplication()); dataChange.setOldConfigValue(storedAudit.getOldvalue()); dataChange.setNewConfigValue(storedAudit.getNewvalue()); dataChangeList.add(dataChange); previousAuditItem = currentAuditItem; } if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); } ConfigPropertyAuditTrail trail = new ConfigPropertyAuditTrail(); trail.setConfigPropertyAudit(auditItemList); return trail; }  @Override ConfigTreeNode listProperties(); @Override @Transactional List<ConfigProperty> addUpdateProperties(ConfigPropertyRequest configPropertyRequest, String user,
			String userMessage, String timeNow, boolean partOfRollbackOperation); @Override @Transactional String deleteProperty(ConfigPropertyItem configPropertyItem, String user, String userMessage, String timeNow,
			boolean partOfRollbackOperation); @Override boolean isAllPropertiesExisting(ConfigPropertyRequest configPropertyRequest); @Override boolean isAnyPropertyExisting(ConfigPropertyRequest configPropertyRequest); @Override boolean isPropertyExisting(ConfigPropertyItem configPropertyItem); @Override boolean isCfkeyExisting(String cfkey); @Override boolean isAllCfkeysExisting(ConfigPropertyRequest configPropertyRequest); @Override boolean isApplicationExisting(String application); @Override boolean isAllApplicationsExisting(ConfigPropertyRequest configPropertyRequest); @Override List<String> listAllKeys(); @Override ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp); @Override ConfigPropertyRollbackPreview getRollbackPreview(String timestamp); @Override @Transactional String doConfigPropertyRollbackToTimestamp(String timestamp, String user, String userMessage); @Override List<ConfigProperty> listProperty(String cfkey, String application); }
ConfigPropertyServiceImpl implements ConfigPropertyService { @Override public ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp) throws Exception { if (StringUtils.isEmpty(timestamp)) { LocalDateTime now = LocalDateTime.now(); timestamp = now.minusMonths(1).format(DateTimeFormatter.ofPattern(DATE_FORMAT)); } List<ConfigPropertyAudit> allStoredAudits = configPropertyAuditRepository .findAllByOrderByModifiedDateDescModifiedByAsc(); Comparator<ConfigPropertyAudit> comp = ((m2, m1) -> LocalDateTime .parse(m1.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)).compareTo( LocalDateTime.parse(m2.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)))); Collections.sort(allStoredAudits, comp); ConfigPropertyAuditItem previousAuditItem = new ConfigPropertyAuditItem(); ConfigPropertyAuditItem currentAuditItem = new ConfigPropertyAuditItem(); List<ConfigPropertyDataChange> dataChangeList = new ArrayList<ConfigPropertyDataChange>(); List<ConfigPropertyAuditItem> auditItemList = new ArrayList<>(); for (ConfigPropertyAudit storedAudit : allStoredAudits) { if (LocalDateTime.parse(storedAudit.getModifiedDate(), DateTimeFormatter.ofPattern(DATE_FORMAT)) .isBefore(LocalDateTime.parse(timestamp, DateTimeFormatter.ofPattern(DATE_FORMAT)))) { break; } if (!(storedAudit.getModifiedDate().equals(previousAuditItem.getAuditTimeStamp()) && storedAudit.getModifiedBy().equals(previousAuditItem.getModifiedBy()))) { if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); currentAuditItem = new ConfigPropertyAuditItem(); dataChangeList = new ArrayList<ConfigPropertyDataChange>(); } } currentAuditItem.setConfigPropertyChangeList(dataChangeList); currentAuditItem.setAuditTimeStamp(storedAudit.getModifiedDate()); currentAuditItem.setModifiedBy(storedAudit.getModifiedBy()); currentAuditItem.setUserMessage(storedAudit.getUserMessage()); currentAuditItem.setSystemMessage(storedAudit.getSystemMessage()); ConfigPropertyDataChange dataChange = new ConfigPropertyDataChange(); dataChange.setConfigKey(storedAudit.getCfkey()); dataChange.setApplication(storedAudit.getApplication()); dataChange.setOldConfigValue(storedAudit.getOldvalue()); dataChange.setNewConfigValue(storedAudit.getNewvalue()); dataChangeList.add(dataChange); previousAuditItem = currentAuditItem; } if (currentAuditItem.getAuditTimeStamp() != null) { auditItemList.add(currentAuditItem); } ConfigPropertyAuditTrail trail = new ConfigPropertyAuditTrail(); trail.setConfigPropertyAudit(auditItemList); return trail; }  @Override ConfigTreeNode listProperties(); @Override @Transactional List<ConfigProperty> addUpdateProperties(ConfigPropertyRequest configPropertyRequest, String user,
			String userMessage, String timeNow, boolean partOfRollbackOperation); @Override @Transactional String deleteProperty(ConfigPropertyItem configPropertyItem, String user, String userMessage, String timeNow,
			boolean partOfRollbackOperation); @Override boolean isAllPropertiesExisting(ConfigPropertyRequest configPropertyRequest); @Override boolean isAnyPropertyExisting(ConfigPropertyRequest configPropertyRequest); @Override boolean isPropertyExisting(ConfigPropertyItem configPropertyItem); @Override boolean isCfkeyExisting(String cfkey); @Override boolean isAllCfkeysExisting(ConfigPropertyRequest configPropertyRequest); @Override boolean isApplicationExisting(String application); @Override boolean isAllApplicationsExisting(ConfigPropertyRequest configPropertyRequest); @Override List<String> listAllKeys(); @Override ConfigPropertyAuditTrail listAllConfigPropertyAudits(String timestamp); @Override ConfigPropertyRollbackPreview getRollbackPreview(String timestamp); @Override @Transactional String doConfigPropertyRollbackToTimestamp(String timestamp, String user, String userMessage); @Override List<ConfigProperty> listProperty(String cfkey, String application);  }