Example usage for com.vaadin.v7.data.util HierarchicalContainer addItem

List of usage examples for com.vaadin.v7.data.util HierarchicalContainer addItem

Introduction

In this page you can find the example usage for com.vaadin.v7.data.util HierarchicalContainer addItem.

Prototype

@Override
    public Item addItem(Object itemId) 

Source Link

Usage

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getNpcPhrasesDiff(List<GSpreadSheetsNpcPhrase> phrases, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }//from   w ww.  j a  v a 2s  . c o m
    hc.removeAllItems();
    List<NpcPhraseDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsNpcPhrase.class);
    Map<Long, GSpreadSheetsNpcPhrase> phrasesMap = new HashMap<>();
    List<GSpreadSheetsNpcPhrase> allPhrases = crit.list();
    for (GSpreadSheetsNpcPhrase phrase : allPhrases) {
        phrasesMap.put(phrase.getRowNum(), phrase);
    }
    for (GSpreadSheetsNpcPhrase phrase : phrases) {
        GSpreadSheetsNpcPhrase result = phrasesMap.get(phrase.getRowNum());
        if (result != null) {
            if (!phrase.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(phrase.getRowNum(), phrase.getTextEn(),
                        result.getTextEn());
            }
            if (phrase.getChangeTime() != null && result.getChangeTime() != null
                    && phrase.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (phrase.getChangeTime() != null && result.getChangeTime() != null
                    && phrase.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && phrase.getChangeTime() == null) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && phrase.getChangeTime() != null) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && phrase.getChangeTime() == null
                    && (phrase.getTextRu() != null) && (result.getTextRu() != null)
                    && !phrase.getTextRu().equals(result.getTextRu())) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (NpcPhraseDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsPhrase().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsPhrase().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsPhrase().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbPhrase().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbPhrase().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbPhrase().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getNpcnamessDiff(List<GSpreadSheetsNpcName> names, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }/*from www.ja va2s .  c  o  m*/
    hc.removeAllItems();
    List<NpcNameDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsNpcName.class);
    Map<Long, GSpreadSheetsNpcName> namesMap = new HashMap<>();
    List<GSpreadSheetsNpcName> allNames = crit.list();
    for (GSpreadSheetsNpcName name : allNames) {
        namesMap.put(name.getRowNum(), name);
    }
    for (GSpreadSheetsNpcName name : names) {
        GSpreadSheetsNpcName result = namesMap.get(name.getRowNum());
        if (result != null) {
            if (!name.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(name.getRowNum(), name.getTextEn(), result.getTextEn());
            }
            if (name.getChangeTime() != null && result.getChangeTime() != null
                    && name.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (name.getChangeTime() != null && result.getChangeTime() != null
                    && name.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && name.getChangeTime() == null) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && name.getChangeTime() != null) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && name.getChangeTime() == null
                    && (name.getTextRu() != null) && (result.getTextRu() != null)
                    && !name.getTextRu().equals(result.getTextRu())) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (name.getSex() != result.getSex()) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (NpcNameDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getLocationNamesDiff(List<GSpreadSheetsLocationName> names,
        HierarchicalContainer hc) throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }/* w ww .  j  a  v a 2 s.  co  m*/
    hc.removeAllItems();
    List<LocationsDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsLocationName.class);
    Map<Long, GSpreadSheetsLocationName> namesMap = new HashMap<>();
    List<GSpreadSheetsLocationName> allNames = crit.list();
    for (GSpreadSheetsLocationName name : allNames) {
        namesMap.put(name.getRowNum(), name);
    }
    for (GSpreadSheetsLocationName name : names) {
        GSpreadSheetsLocationName result = namesMap.get(name.getRowNum());
        if (result != null) {
            if (!name.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(name.getRowNum(), name.getTextEn(), result.getTextEn());
            }
            if (name.getChangeTime() != null && result.getChangeTime() != null
                    && name.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new LocationsDiff(name, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (name.getChangeTime() != null && result.getChangeTime() != null
                    && name.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new LocationsDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && name.getChangeTime() == null) {
                diffs.add(new LocationsDiff(name, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && name.getChangeTime() != null) {
                diffs.add(new LocationsDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && name.getChangeTime() == null
                    && (name.getTextRu() != null) && (result.getTextRu() != null)
                    && !name.getTextRu().equals(result.getTextRu())) {
                diffs.add(new LocationsDiff(name, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (LocationsDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getQuestNamesDiff(List<GSpreadSheetsQuestName> items, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }//from  ww  w  . j a v a  2  s  .c o  m
    hc.removeAllItems();
    List<QuestNamesDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsQuestName.class);
    Map<Long, GSpreadSheetsQuestName> itemMap = new HashMap<>();
    List<GSpreadSheetsQuestName> allItems = crit.list();
    for (GSpreadSheetsQuestName item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsQuestName item : items) {
        GSpreadSheetsQuestName result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new QuestNamesDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new QuestNamesDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new QuestNamesDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new QuestNamesDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new QuestNamesDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (QuestNamesDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getQuestDescriptionsDiff(List<GSpreadSheetsQuestDescription> items,
        HierarchicalContainer hc) throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }/*from  w w  w. j a  v a 2 s.  c  o  m*/
    hc.removeAllItems();
    List<QuestDescriptionsDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsQuestDescription.class);
    Map<Long, GSpreadSheetsQuestDescription> itemMap = new HashMap<>();
    List<GSpreadSheetsQuestDescription> allItems = crit.list();
    for (GSpreadSheetsQuestDescription item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsQuestDescription item : items) {
        GSpreadSheetsQuestDescription result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new QuestDescriptionsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new QuestDescriptionsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new QuestDescriptionsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new QuestDescriptionsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new QuestDescriptionsDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (QuestDescriptionsDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getQuestDirectionsDiff(List<GSpreadSheetsQuestDirection> items,
        HierarchicalContainer hc) throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }/*w w w .  jav  a 2 s .c o m*/
    hc.removeAllItems();
    List<QuestDirectionsDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsQuestDirection.class);
    Map<Long, GSpreadSheetsQuestDirection> itemMap = new HashMap<>();
    List<GSpreadSheetsQuestDirection> allItems = crit.list();
    for (GSpreadSheetsQuestDirection item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsQuestDirection item : items) {
        GSpreadSheetsQuestDirection result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new QuestDirectionsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new QuestDirectionsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new QuestDirectionsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new QuestDirectionsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new QuestDirectionsDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (QuestDirectionsDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getItemNamesDiff(List<GSpreadSheetsItemName> items, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }//from ww  w .  j a va  2s . com
    hc.removeAllItems();
    List<ItemNamesDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsItemName.class);
    Map<Long, GSpreadSheetsItemName> itemMap = new HashMap<>();
    List<GSpreadSheetsItemName> allItems = crit.list();
    for (GSpreadSheetsItemName item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsItemName item : items) {
        GSpreadSheetsItemName result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new ItemNamesDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new ItemNamesDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new ItemNamesDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new ItemNamesDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new ItemNamesDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (ItemNamesDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getItemDescriptionsDiff(List<GSpreadSheetsItemDescription> items,
        HierarchicalContainer hc) throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }//  w w w.  jav  a 2 s.  c  o  m
    hc.removeAllItems();
    List<ItemDescriptionsDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsItemDescription.class);
    Map<Long, GSpreadSheetsItemDescription> itemMap = new HashMap<>();
    List<GSpreadSheetsItemDescription> allItems = crit.list();
    for (GSpreadSheetsItemDescription item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsItemDescription item : items) {
        GSpreadSheetsItemDescription result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new ItemDescriptionsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new ItemDescriptionsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new ItemDescriptionsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new ItemDescriptionsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new ItemDescriptionsDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (ItemDescriptionsDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getActivatorsDiff(List<GSpreadSheetsActivator> items, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }//from  ww  w.jav a 2s. co m
    hc.removeAllItems();
    List<ActivatorsDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsActivator.class);
    Map<Long, GSpreadSheetsActivator> itemMap = new HashMap<>();
    List<GSpreadSheetsActivator> allItems = crit.list();
    for (GSpreadSheetsActivator item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsActivator item : items) {
        GSpreadSheetsActivator result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new ActivatorsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new ActivatorsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new ActivatorsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new ActivatorsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new ActivatorsDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (ActivatorsDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getAchievementsDiff(List<GSpreadSheetsAchievement> items, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        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);
    }/*w w  w  .j a va  2  s .com*/
    hc.removeAllItems();
    List<AchievementsDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsAchievement.class);
    Map<Long, GSpreadSheetsAchievement> itemMap = new HashMap<>();
    List<GSpreadSheetsAchievement> allItems = crit.list();
    for (GSpreadSheetsAchievement item : allItems) {
        itemMap.put(item.getRowNum(), item);
    }
    for (GSpreadSheetsAchievement item : items) {
        GSpreadSheetsAchievement result = itemMap.get(item.getRowNum());
        if (result != null) {
            if (!item.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(item.getRowNum(), item.getTextEn(), result.getTextEn());
            }
            if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new AchievementsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (item.getChangeTime() != null && result.getChangeTime() != null
                    && item.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new AchievementsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && item.getChangeTime() == null) {
                diffs.add(new AchievementsDiff(item, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && item.getChangeTime() != null) {
                diffs.add(new AchievementsDiff(item, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && item.getChangeTime() == null
                    && (item.getTextRu() != null) && (result.getTextRu() != null)
                    && !item.getTextRu().equals(result.getTextRu())) {
                diffs.add(new AchievementsDiff(item, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (AchievementsDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}