Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/web/jsp/TopicPage.java @ 43:9dbbbfd474f4
new: 1.existing topic in search result. 2.difference-set of book for topic
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 23 Dec 2015 16:03:32 +0100 |
parents | 815cd86bb9ec |
children | 89d1076df1c3 |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/web/jsp/TopicPage.java Fri Dec 18 11:50:24 2015 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/TopicPage.java Wed Dec 23 16:03:32 2015 +0100 @@ -1,8 +1,10 @@ package de.mpiwg.web.jsp; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -18,6 +20,7 @@ import de.mpiwg.gazetteer.bo.LGTopicSectionRelation; import de.mpiwg.gazetteer.dataverse.DataverseUtils; import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.db.DBBook; import de.mpiwg.gazetteer.db.DBSection; import de.mpiwg.gazetteer.utils.DBService; import de.mpiwg.gazetteer.utils.DataProvider; @@ -67,6 +70,11 @@ private Map<Long, List<LGBranch>> branchesMap; + private Map<String, DBBook> booksMap; + + private List<DBBook> pendingBookList; + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ this.request = request; @@ -160,6 +168,8 @@ if(topic != null && topic.isPersistent()){ this.loadBranches(); + this.loadBooks(); + try { this.topic = (LGTopic)topic.clone(); @@ -184,6 +194,21 @@ logger.info("completeSectionList.size=" + completeSectionList.size()); } this.filter(); + + + // pendingBookList + for(DBSection section :this.completeSectionList) { + String bookId = section.getBookId(); + + if (this.booksMap.get(bookId) != null) { + // remove the book with bookId from pendingBookList + this.booksMap.remove(bookId); + } + } + + this.pendingBookList = new ArrayList<DBBook>(); + this.pendingBookList.addAll(this.booksMap.values()); + } @@ -295,10 +320,12 @@ } */ - for(DBSection section : this.displaySectionList){ - section.setBranches(this.branchesMap.get(section.getId())); + //for(DBSection section : this.displaySectionList){ + for(DBSection section : this.completeSectionList){ // we don't paginate now + section.setBranches(this.branchesMap.get(section.getId())); } + } @@ -312,7 +339,6 @@ String status = DataProvider.getInstance().updateTopicSectionRelation(_sectionId, _topicId); if (StringUtils.equals(status, "added") ) { - // TODO responding with names to user addMsg("Added section [id=" + _sectionId + "] to the topic [id=" + _topicId + "]"); } else if (StringUtils.equals(status, "updated") ) { addMsg("The section already in the topic"); @@ -335,9 +361,58 @@ this.branchesMap.put(branch.getSectionId(), new ArrayList<LGBranch>()); } this.branchesMap.get(branch.getSectionId()).add(branch); + } } + + private void loadBooks(){ + + List<DBBook> bookList = DBService.getInstance().getBooks(); + + this.booksMap = new HashMap<String, DBBook>(); + + for (DBBook book : bookList) { + + this.booksMap.put(book.getId(), book); + + } + + } + + + + public void addAllSectionsToTopic(List<DBSection> list, Long selectedTopicId) throws Exception { + + if (list == null) { + return; + } + logger.debug("selectedTopicId: " + selectedTopicId + ", total " + list.size() + " sections."); + + Integer added = 0; + Integer existing = 0; + + for (DBSection section : list) { + // create a new record in TopicSectionRelation table + String status = DataProvider.getInstance().updateTopicSectionRelation(section.getId(), selectedTopicId); + + if (StringUtils.equals(status, "added") ) { + added++; + } else if (StringUtils.equals(status, "updated") ) { + existing++; + } + + } + + addMsg("Added " + added.toString() + " sections. " + existing.toString() + " sections already in the topic."); + + this.reset(); + } + + + + + public List<VDCUser> getContributors() { return contributors; } @@ -538,21 +613,36 @@ } + + + + public List<DBBook> getPendingBookList() { + return pendingBookList; + } + + + + public void setPendingBookList(List<DBBook> pendingBookList) { + this.pendingBookList = pendingBookList; + } + + public List<DBSection> getCompleteSectionList() { return completeSectionList; } - - public void setCompleteSectionList(List<DBSection> completeSectionList) { this.completeSectionList = completeSectionList; } + + + + /////// Sorting - public void sortByBookNameUp(){ Collections.sort(this.completeSectionList, new SortSectionByBookName()); @@ -669,6 +759,18 @@ filter(); } + + public void updateKeywords() { + String keywords = getParameter("keywords"); + this.getTopic().setKeywords(keywords); + + this.saveTopic0(); + + } + + + +