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

import static com.heroku.myapp.commons.config.enumerate.Kind.koepota_seiyu_all;
import static com.heroku.myapp.commons.config.enumerate.Kind.seiyu_has_recentchanges;
import com.heroku.myapp.commons.consumers.SnapshotQueueConsumer;
import com.heroku.myapp.commons.util.actions.MasterUtil;
import com.heroku.myapp.commons.util.content.DocumentUtil;
import java.util.ArrayList;
import java.util.Optional;
import org.apache.camel.Exchange;
import org.bson.Document;
import org.springframework.stereotype.Component;

@Component
public class SnapshotGoogleTrendsSeiyuAllConsumer extends SnapshotQueueConsumer {

    @Override
    protected Optional<Document> doSnapshot(Exchange exchange) {
        try {
            MasterUtil masterUtil = new MasterUtil(exchange);
            Document latest = masterUtil.optionalLatest()
                    .orElse(new Document("data", new ArrayList<>()));
            DocumentUtil util = new DocumentUtil();
            Document product = util.productByTitle(
                    masterUtil.findOrElseThrow(koepota_seiyu_all),
                    masterUtil.findOrElseThrow(seiyu_has_recentchanges))
                    .getDocument();
            return util.addNewByKey(latest, product, "title").nullable();
        } catch (Exception ex) {
            util().sendError("doSnapshot", ex);
            return Optional.empty();
        }
    }
}

@@ -207,33 +207,128 @@
 d.seiyu_
-has_recentchanges
+category_members_include_template;%0Aimport static com.heroku.myapp.commons.config.enumerate.Kind.seiyu_multi_lang
 ;%0Aimport
@@ -547,24 +547,127 @@
 va.util.
-Optional
+List;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors
 ;%0Aimport
@@ -1019,16 +1019,68 @@
 hange);%0A
+            DocumentUtil util = new DocumentUtil();%0A
         
@@ -1215,47 +1215,878 @@
     
-DocumentUtil util = new DocumentUtil();
+Set keySet = util.setDocument(masterUtil%0A                    .findOrElseThrow(koepota_seiyu_all)).keySet(%22title%22);%0A            util.setDocument(masterUtil%0A                    .findOrElseThrow(seiyu_multi_lang)).getData()%0A                    .stream().filter((map) -%3E %7B%0A                        List langlinks = (List) map.get(%22langlinks%22);%0A                        return langlinks != null && langlinks.size() %3E 1;%0A                    %7D)%0A                    .map((map) -%3E map.get(%22title%22))%0A                    .forEach(keySet::add);%0A            List%3CMap%3CString, Object%3E%3E product%0A                    = util.setDocument(masterUtil.findOrElseThrow(%0A                            seiyu_category_members_include_template)).getData()%0A                    .stream().filter((map) -%3E keySet.contains(map.get(%22title%22)))%0A                    .collect(Collectors.toList());%0A            /*
 %0A   
@@ -2309,16 +2309,18 @@
 ument();
+*/
 %0A       

modify Kind.google_trends_seiyu_all logic