Exemple #1
0
 @Scheduled(fixedDelay = 1800000, initialDelay = 2000)
 public void execute() throws OriginalTextMismatchException {
   if (dbService.getIsAutoSynchronizationEnabled()) {
     LOG.info("automatic sync enabled");
     HierarchicalContainer hc = new HierarchicalContainer();
     hc.addContainerProperty("shText", String.class, null);
     hc.addContainerProperty("shNic", String.class, null);
     hc.addContainerProperty("shDate", Date.class, null);
     hc.addContainerProperty("dbText", String.class, null);
     hc.addContainerProperty("dbNic", String.class, null);
     hc.addContainerProperty("dbDate", Date.class, null);
     hc.addContainerProperty("syncType", String.class, null);
     LOG.info("loading " + TABLE_NAME);
     List<GSpreadSheetsNote> items = docsService.getNotes();
     LOG.info("making diff for " + TABLE_NAME);
     hc = dbService.getNotesDiff(items, hc);
     List<NotesDiff> diffs = (List<NotesDiff>) hc.getItemIds();
     List<GSpreadSheetsNote> itemsToSh = new ArrayList<>();
     List<GSpreadSheetsNote> itemsToDb = new ArrayList<>();
     for (NotesDiff diff : diffs) {
       if (diff.getSyncType() == SYNC_TYPE.TO_SPREADSHEET) {
         itemsToSh.add(diff.getDbName());
       } else if (diff.getSyncType() == SYNC_TYPE.TO_DB) {
         itemsToDb.add(diff.getSpreadsheetsName());
       }
     }
     LOG.log(Level.INFO, "uploading {0}" + " " + TABLE_NAME, itemsToSh.size());
     docsService.uploadNotes(itemsToSh);
     LOG.log(Level.INFO, "saving to db {0}" + " " + TABLE_NAME, itemsToDb.size());
     dbService.saveNotes(itemsToDb);
     LOG.info("sync finished for " + TABLE_NAME);
     hc.removeAllItems();
   } else {
     LOG.info("automatic sync disabled");
   }
 }