@Test public void queryAlfrescoAuditApplications() throws Exception { Long firstAppAuditId = Integer.valueOf(new Random().nextInt(10000 - 10) + 10).longValue(); Long secondAppAuditId = Integer.valueOf(new Random().nextInt(10000 - 10) + 10).longValue(); expect(propertyFileManager.load(auditApplicationLastAuditIdProperties, "applicationOne.lastAuditId", "0")) .andReturn(String.valueOf(firstAppAuditId)); expect(propertyFileManager.load(auditApplicationLastAuditIdProperties, "applicationTwo.lastAuditId", "0")) .andReturn(String.valueOf(secondAppAuditId)); expect(auditApplicationRestClient.service("applicationOne", firstAppAuditId + 1)).andReturn(firstAuditResponse); expect(auditApplicationRestClient.service("applicationTwo", secondAppAuditId + 1)).andReturn(secondAuditResponse); propertyFileManager.storeMultiple( Collections.singletonMap("applicationOne.lastAuditId", "61"), auditApplicationLastAuditIdProperties, false); propertyFileManager.storeMultiple( Collections.singletonMap("applicationTwo.lastAuditId", "91"), auditApplicationLastAuditIdProperties, false); Capture<EcmEvent> first = Capture.newInstance(); Capture<EcmEvent> second = Capture.newInstance(); Capture<EcmEvent> third = Capture.newInstance(); Capture<EcmEvent> fourth = Capture.newInstance(); Capture<EcmEvent> fifth = Capture.newInstance(); applicationEventPublisher.publishEvent(capture(first)); applicationEventPublisher.publishEvent(capture(second)); applicationEventPublisher.publishEvent(capture(third)); applicationEventPublisher.publishEvent(capture(fourth)); applicationEventPublisher.publishEvent(capture(fifth)); replay(propertyFileManager, auditApplicationRestClient, applicationEventPublisher); unit.queryAlfrescoAuditApplications(); verify(propertyFileManager, auditApplicationRestClient, applicationEventPublisher); assertEquals(42, first.getValue().getAuditId()); assertEquals(52, second.getValue().getAuditId()); assertEquals(55, third.getValue().getAuditId()); assertEquals(57, fourth.getValue().getAuditId()); assertEquals(91, fifth.getValue().getAuditId()); }
public void queryAlfrescoAuditApplications() { if (MDC.get(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY) == null) { MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, "admin"); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); } List<EcmEvent> allEvents = new ArrayList<>(); for (Map.Entry<String, EcmAuditResponseReader> auditApplication : getAuditApplications().entrySet()) { List<EcmEvent> eventsForAuditApp = collectAuditEvents(auditApplication.getKey(), auditApplication.getValue()); if (eventsForAuditApp != null && !eventsForAuditApp.isEmpty()) { log.info("Fetched {} audit records for audit application {}", eventsForAuditApp.size(), auditApplication.getKey()); allEvents.addAll(eventsForAuditApp); } } allEvents.stream().sorted(Comparator.comparing(EcmEvent::getAuditId)).forEach(e -> applicationEventPublisher.publishEvent(e)); }
AlfrescoSyncService implements ApplicationEventPublisherAware { public void queryAlfrescoAuditApplications() { if (MDC.get(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY) == null) { MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, "admin"); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); } List<EcmEvent> allEvents = new ArrayList<>(); for (Map.Entry<String, EcmAuditResponseReader> auditApplication : getAuditApplications().entrySet()) { List<EcmEvent> eventsForAuditApp = collectAuditEvents(auditApplication.getKey(), auditApplication.getValue()); if (eventsForAuditApp != null && !eventsForAuditApp.isEmpty()) { log.info("Fetched {} audit records for audit application {}", eventsForAuditApp.size(), auditApplication.getKey()); allEvents.addAll(eventsForAuditApp); } } allEvents.stream().sorted(Comparator.comparing(EcmEvent::getAuditId)).forEach(e -> applicationEventPublisher.publishEvent(e)); } }
AlfrescoSyncService implements ApplicationEventPublisherAware { public void queryAlfrescoAuditApplications() { if (MDC.get(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY) == null) { MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, "admin"); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); } List<EcmEvent> allEvents = new ArrayList<>(); for (Map.Entry<String, EcmAuditResponseReader> auditApplication : getAuditApplications().entrySet()) { List<EcmEvent> eventsForAuditApp = collectAuditEvents(auditApplication.getKey(), auditApplication.getValue()); if (eventsForAuditApp != null && !eventsForAuditApp.isEmpty()) { log.info("Fetched {} audit records for audit application {}", eventsForAuditApp.size(), auditApplication.getKey()); allEvents.addAll(eventsForAuditApp); } } allEvents.stream().sorted(Comparator.comparing(EcmEvent::getAuditId)).forEach(e -> applicationEventPublisher.publishEvent(e)); }  }
AlfrescoSyncService implements ApplicationEventPublisherAware { public void queryAlfrescoAuditApplications() { if (MDC.get(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY) == null) { MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, "admin"); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); } List<EcmEvent> allEvents = new ArrayList<>(); for (Map.Entry<String, EcmAuditResponseReader> auditApplication : getAuditApplications().entrySet()) { List<EcmEvent> eventsForAuditApp = collectAuditEvents(auditApplication.getKey(), auditApplication.getValue()); if (eventsForAuditApp != null && !eventsForAuditApp.isEmpty()) { log.info("Fetched {} audit records for audit application {}", eventsForAuditApp.size(), auditApplication.getKey()); allEvents.addAll(eventsForAuditApp); } } allEvents.stream().sorted(Comparator.comparing(EcmEvent::getAuditId)).forEach(e -> applicationEventPublisher.publishEvent(e)); }  void queryAlfrescoAuditApplications(); PropertyFileManager getPropertyFileManager(); void setPropertyFileManager(PropertyFileManager propertyFileManager); AlfrescoAuditApplicationRestClient getAuditApplicationRestClient(); void setAuditApplicationRestClient(AlfrescoAuditApplicationRestClient auditApplicationRestClient); String getAuditApplicationLastAuditIdsFilename(); void setAuditApplicationLastAuditIdsFilename(String auditApplicationLastAuditIdsFilename); @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); Map<String, EcmAuditResponseReader> getAuditApplications(); void setAuditApplications(Map<String, EcmAuditResponseReader> auditApplications); }
AlfrescoSyncService implements ApplicationEventPublisherAware { public void queryAlfrescoAuditApplications() { if (MDC.get(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY) == null) { MDC.put(MDCConstants.EVENT_MDC_REQUEST_ALFRESCO_USER_ID_KEY, "admin"); MDC.put(MDCConstants.EVENT_MDC_REQUEST_ID_KEY, UUID.randomUUID().toString()); } List<EcmEvent> allEvents = new ArrayList<>(); for (Map.Entry<String, EcmAuditResponseReader> auditApplication : getAuditApplications().entrySet()) { List<EcmEvent> eventsForAuditApp = collectAuditEvents(auditApplication.getKey(), auditApplication.getValue()); if (eventsForAuditApp != null && !eventsForAuditApp.isEmpty()) { log.info("Fetched {} audit records for audit application {}", eventsForAuditApp.size(), auditApplication.getKey()); allEvents.addAll(eventsForAuditApp); } } allEvents.stream().sorted(Comparator.comparing(EcmEvent::getAuditId)).forEach(e -> applicationEventPublisher.publishEvent(e)); }  void queryAlfrescoAuditApplications(); PropertyFileManager getPropertyFileManager(); void setPropertyFileManager(PropertyFileManager propertyFileManager); AlfrescoAuditApplicationRestClient getAuditApplicationRestClient(); void setAuditApplicationRestClient(AlfrescoAuditApplicationRestClient auditApplicationRestClient); String getAuditApplicationLastAuditIdsFilename(); void setAuditApplicationLastAuditIdsFilename(String auditApplicationLastAuditIdsFilename); @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); Map<String, EcmAuditResponseReader> getAuditApplications(); void setAuditApplications(Map<String, EcmAuditResponseReader> auditApplications);  }