package com.heroku.myapp.myorchestrator.consumers.snapshot.seiyu;

import com.heroku.myapp.commons.consumers.DiffQueueConsumer;
import com.heroku.myapp.commons.util.content.DocumentUtil;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bson.Document;
import org.springframework.stereotype.Component;

@Component
public class DiffRecentchangesOfSeiyuConsumer extends DiffQueueConsumer {

    @Override
    public Optional<Document> calculateDiff(Document master, Document snapshot) {
        List<Map<String, Object>> newList = new DocumentUtil().setDocument(snapshot).getData();
        List<Map<String, Object>> oldList = new DocumentUtil().setDocument(master).getData();
        Map<Object, Map<String, Object>> oldMap = new LinkedHashMap<>();
        oldList.stream().forEach((map) -> oldMap.put(oldMap.get("title"), map));
        List<Map<String, Object>> collect = newList.stream().filter((map) -> {
            Object title = map.get("title");
            if (oldMap.containsKey(title)) {
                Object old_revid = map.get("old_revid");
                Map<String, Object> old = oldMap.get(title);
                if (old.get("revid").equals(old_revid)) {
                    return true;
                } else {
                    throw new RuntimeException();
                }
            } else {
                return true;
            }
        }).collect(Collectors.toList());
        if (collect.isEmpty()) {
            return Optional.empty();
        } else {
            return new DocumentUtil().setDiff(collect).nullable();
        }
    }
}

@@ -1057,24 +1057,106 @@
          if 
+(!map.containsKey(%22revid%22)) %7B%0A                return false;%0A            %7D else if 
 (oldMap.cont
@@ -1193,49 +1193,47 @@
     
-Object old_revid = map.get(%22old_revid%22);%0A
+if (oldMap.containsKey(%22revid%22)) %7B%0A    
     
@@ -1301,24 +1301,28 @@
             
+    
 if (old.get(
@@ -1337,16 +1337,25 @@
 .equals(
+map.get(%22
 old_revi
@@ -1355,21 +1355,27 @@
 ld_revid
+%22)
 )) %7B%0A
+    
         
@@ -1407,32 +1407,36 @@
                 
+ 
+   
 %7D else %7B%0A       
@@ -1420,32 +1420,36 @@
        %7D else %7B%0A
+    
                 
@@ -1478,24 +1478,104 @@
 xception();%0A
+                    %7D%0A                %7D else %7B%0A                    return true;%0A
             

modify DiffRecentchangesOfSeiyuConsumer logic