annotate src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java @ 105:16a0796e3871 default tip

remove "console.log" from general.js
author Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
date Fri, 29 Sep 2017 16:18:02 +0200
parents f4242db6206b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
1 package de.mpiwg.gazetteer.utils;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
2
54
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
3 import java.io.IOException;
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
4 import java.sql.SQLException;
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
5 import java.util.ArrayList;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
6 import java.util.Collections;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
7 import java.util.Date;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
8 import java.util.List;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
9
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
10 import org.apache.log4j.Logger;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
11 import org.hibernate.Session;
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
12 import org.hibernate.Transaction;
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
13
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
14 import cl.maps.duplex.DuplexKey;
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
15 import de.mpiwg.gazetteer.bo.LGBranch;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
16 import de.mpiwg.gazetteer.bo.LGFile;
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
17 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
55
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
18 import de.mpiwg.gazetteer.bo.LGTaglist;
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
19 import de.mpiwg.gazetteer.bo.LGTopic;
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
20 import de.mpiwg.gazetteer.bo.LGTopicSectionRelation;
55
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
21 import de.mpiwg.gazetteer.bo.LGTopicTagRelation;
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
22 import de.mpiwg.gazetteer.db.DBContents;
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
23 import de.mpiwg.gazetteer.db.DBSection;
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
24 import de.mpiwg.gazetteer.utils.exceptions.NoAuthorizedException;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
25 import de.mpiwg.gazetteer.utils.exceptions.VersioningException;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
26
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
27 public class DataProvider extends AbstractDataProvider{
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
28
43
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
29 private static Logger logger = Logger.getLogger(DataProvider.class);
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
30 private static DataProvider instance;
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
31
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
32 public static DataProvider getInstance(){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
33 if(instance == null)
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
34 instance = new DataProvider();
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
35 return instance;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
36 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
37
34
2e1662afc81c new: add synchronization for files uploaded to LGDataverse
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 26
diff changeset
38 public static void resetInstance() {
2e1662afc81c new: add synchronization for files uploaded to LGDataverse
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 26
diff changeset
39 instance = null;
2e1662afc81c new: add synchronization for files uploaded to LGDataverse
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 26
diff changeset
40 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
41
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
42 public DataProvider(){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
43 logger.info("##### Starting DataProvider #####");
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
44 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
45
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
46
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
47
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
48 /* --- branch --- */
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
49
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
50 public LGFile getFile(Long fileId){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
51 return getFileMap().getValuesByOwnKey(fileId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
52 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
53
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
54 public List<LGFile> getAllFiles(Long branchId){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
55 List<LGFile> list = getFileMap().getValuesByAKey(branchId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
56 Collections.sort(list);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
57 Collections.reverse(list);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
58 return list;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
59 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
60
43
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
61 public List<LGTopicSectionRelation> getAllExistingTopicSectionRelation() {
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
62 List<LGTopicSectionRelation> list = new ArrayList<LGTopicSectionRelation>();
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
63 for (LGTopicSectionRelation relation : getTopicSectionRelationMap().values()) {
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
64 list.add(relation);
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
65 }
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
66 return list;
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
67 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
68
38
8b7a204fa929 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 37
diff changeset
69 public List<LGBranch> getAllExistingBranches(){
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
70 List<LGBranch> list = new ArrayList<LGBranch>();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
71 for(LGBranch branch : getBranchMap().values()){
37
ed215307f426 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 34
diff changeset
72 list.add(branch);
ed215307f426 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 34
diff changeset
73 }
ed215307f426 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 34
diff changeset
74 return list;
ed215307f426 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 34
diff changeset
75 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
76
37
ed215307f426 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 34
diff changeset
77 public List<LGBranch> getBranches(Long userId){
ed215307f426 new: show all existing branches in the searching result page of search for sections
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 34
diff changeset
78 List<LGBranch> list = new ArrayList<LGBranch>();
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
79 for(LGBranch branch : getBranchMap().values()){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
80 if(branch.hasContributor(userId)){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
81 list.add(branch);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
82 }
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
83 }
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
84 return list;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
85 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
86
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
87
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
88 public LGBranch getBranch(Long branchId){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
89 return getBranchMap().getValuesByOwnKey(branchId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
90 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
91
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
92 public void deleteFile(LGFile file) throws Exception{
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
93
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
94 LGBranch branch = getBranch(file.getBranchId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
95
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
96 if(branch == null){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
97 throw new Exception("There is any Branch for " + file);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
98 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
99
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
100 List<LGFile> files = getAllFiles(file.getBranchId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
101
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
102 if(files.size() == 1){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
103 throw new Exception("This file could not be deleted, because it is part of a branch that has only one file. A Branch without files is a inconsistency.");
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
104 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
105
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
106 // if the file is the last version of a branch, we must replace the current file with the penultimate file.
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
107 if(branch.getCurrentLastFileId().equals(file.getId())){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
108 LGFile penultimateFile = getPenultimateFile(files);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
109
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
110 penultimateFile.setLastVersion(true);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
111 branch.setCurrentLastFileId(penultimateFile.getId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
112
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
113 this.updateBranch(branch);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
114 this.updateFile(penultimateFile);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
115
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
116 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
117
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
118 //deleting file from DB and cache
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
119 int modifiedFiles = DBService.deleteFileFromDB(file.getId());
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
120 getFileMap().remove(file.getKey());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
121
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
122 logger.info(modifiedFiles + " items deleted by removing file " + file);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
123 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
124
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
125 private LGFile getPenultimateFile(List<LGFile> files){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
126 LGFile penultimateFile = null;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
127 LGFile lastFile = null;
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
128
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
129 for(LGFile file : files){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
130 if(lastFile == null){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
131 lastFile = file;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
132 }else if(penultimateFile == null){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
133 lastFile = (lastFile.getVersion() > file.getVersion()) ? lastFile : file;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
134 penultimateFile = (lastFile.getVersion() < file.getVersion()) ? lastFile : file;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
135 }else{
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
136 if(file.getVersion() > lastFile.getVersion()){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
137 penultimateFile = lastFile;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
138 lastFile = file;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
139 }else if(file.getVersion() > penultimateFile.getVersion()){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
140 penultimateFile = file;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
141 }
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
142 }
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
143 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
144
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
145 return penultimateFile;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
146 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
147
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
148 public void deleteBranch(LGBranch branch){
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
149
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
150 int modifiedFiles = DBService.deleteBranchFromDB(branch.getId());
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
151 List<LGFile> fileToDelete = getFileMap().getValuesByAKey(branch.getId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
152
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
153 for(LGFile file : new ArrayList<LGFile>(fileToDelete)){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
154 getFileMap().remove(file.getKey());
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
155 }
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
156 getBranchMap().remove(branch.getKey());
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
157
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
158 logger.info(modifiedFiles + " items deleted by removing branch " + branch.toString());
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
159 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
160
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
161 public void updateFile(LGFile file) throws Exception{
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
162 if(!file.isPersistent()){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
163 throw new Exception("Trying to update a file that it is not persistent!");
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
164 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
165
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
166 Date date = new Date();
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
167 DBService.saveDBEntry(file, date);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
168 this.getFileMap().put(file.getKey(), file);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
169 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
170
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
171 public void updateBranch(LGBranch branch) throws Exception{
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
172 if(!branch.isPersistent()){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
173 throw new Exception("Trying to update a branch that it is not persistent!");
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
174 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
175
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
176 Date date = new Date();
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
177 DBService.saveDBEntry(branch, date);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
178 this.getBranchMap().put(branch.getKey(), branch);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
179 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
180
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
181 public LGFile saveFile(Long branchId, String text, Long userId, Long userPreviousFileId) throws Exception{
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
182
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
183 Date date = new Date();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
184
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
185 LGBranch branch = getBranchMap().getValuesByOwnKey(branchId);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
186
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
187 if(!branch.hasContributor(userId)){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
188 throw new NoAuthorizedException(userId, branchId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
189 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
190
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
191 if(!branch.getCurrentLastFileId().equals(userPreviousFileId)){
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
192 LGFile userPreviousFile = getFileMap().getValuesByOwnKey(userPreviousFileId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
193 LGFile currentLastFile = getFileMap().getValuesByOwnKey(branch.getCurrentLastFileId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
194
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
195 throw new VersioningException(userPreviousFile, currentLastFile);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
196 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
197
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
198 LGFile previousFile = getFileMap().getValuesByOwnKey(branch.getCurrentLastFileId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
199
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
200 LGFile file = new LGFile();
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
201 file.setBranchId(branchId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
202 file.setVersion(previousFile.getVersion() + 1);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
203 file.setUserId(userId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
204 file.setContent(text);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
205
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
206 //Saving into DB
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
207 //##################################
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
208 Session session = HibernateUtil.getSessionFactory().openSession();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
209 Transaction tx = null;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
210
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
211 try{
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
212
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
213 tx = session.beginTransaction();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
214
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
215 file.setBranchId(branch.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
216 DBService.saveDBEntry0(session, file, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
217
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
218 previousFile.setLastVersion(false);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
219 DBService.saveDBEntry0(session, previousFile, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
220
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
221 branch.setCurrentLastFileId(file.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
222 DBService.saveDBEntry0(session, branch, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
223
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
224 //Saving physical file in the operating system
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
225 String fileName = FileManager.saveFile(branch, file, date, userId);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
226 file.setFileName(fileName);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
227
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
228 DBService.saveDBEntry0(session, file, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
229
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
230 tx.commit();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
231
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
232 //##################################
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
233
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
234 //Saving into Cache
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
235 getBranchMap().put(branch.getKey(), branch);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
236 getFileMap().put(file.getKey(), file);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
237 getFileMap().put(previousFile.getKey(), previousFile);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
238
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
239 }catch (Exception e) {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
240
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
241 if (tx!=null) tx.rollback();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
242
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
243 e.printStackTrace();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
244
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
245 throw e;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
246
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
247 }finally {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
248 session.close();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
249 }
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
250
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
251 return file;
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
252 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
253
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
254 public Long saveNewFile(String text, String label, Long sectionId, Long userId) throws Exception{
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
255
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
256 Date date = new Date();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
257
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
258 LGBranch branch = new LGBranch();
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
259 branch.setSectionId(sectionId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
260 branch.setUserId(userId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
261 branch.setLabel(label);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
262 branch.addContributor(userId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
263 branch.loadTransientData();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
264
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
265 LGFile file = new LGFile();
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
266 file.setUserId(userId);
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
267 file.setContent(text);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
268
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
269 //Saving into DB
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
270 //##################################
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
271 Session session = HibernateUtil.getSessionFactory().openSession();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
272 Transaction tx = null;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
273 try{
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
274 tx = session.beginTransaction();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
275
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
276 DBService.saveDBEntry0(session, branch, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
277 file.setBranchId(branch.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
278
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
279 DBService.saveDBEntry0(session, file, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
280 branch.setCurrentLastFileId(file.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
281
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
282 //Saving physical file in the operating system
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
283 String fileName = FileManager.saveFile(branch, file, date, userId);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
284 file.setFileName(fileName);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
285 DBService.saveDBEntry0(session, file, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
286
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
287 tx.commit();
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
288
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
289 //Saving into Cache
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
290 getBranchMap().put(branch.getKey(), branch);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
291 getFileMap().put(file.getKey(), file);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
292
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
293 }catch (Exception e) {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
294 if (tx!=null) tx.rollback();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
295
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
296 e.printStackTrace();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
297
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
298 throw e;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
299 }finally {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
300 session.close();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
301 }
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
302 //##################################
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
303
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
304 return branch.getId();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
305
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
306 }
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
307
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
308 /* --- end branch --- */
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
309
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
310
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
311
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
312 /* --- full text search --- */
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
313
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
314 public List<LGFullTextSearchFile> getSearchFileList4User(Long userId) {
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
315
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
316 List<LGFullTextSearchFile> list = new ArrayList<LGFullTextSearchFile>();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
317
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
318 for(LGFullTextSearchFile searchFile : getFullTextSearchFileMap().values()){
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
319 if(searchFile.getUserId() == userId){
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
320 list.add(searchFile);
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
321 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
322 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
323
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
324 return list;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
325 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
326
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
327
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
328
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
329
54
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
330 public void deleteLGFullTextSearchFile(LGFullTextSearchFile file) throws IOException{
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
331 //deleting file from DB: the record in table FullTextSearchFile
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
332 int modifiedFiles = DBService.deleteFullTextSearchFileFromDB(file.getId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
333
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
334 // delete the files from file system (html in ftsearch-data/... and csv in LGMap/datasets/)
54
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
335 FileManager.deleteFullTextSearchFileCsv(file);
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
336 FileManager.deleteFullTextSearchFileHtml(file);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
337
54
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
338 // delete file from cache
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
339 this.getFullTextSearchFileMap().remove(file.getKey());
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
340 logger.debug("deleteLGFullTextSearchFile");
a00efd5d9e77 new: adding delete saved table function
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 49
diff changeset
341 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
342
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
343 public LGFullTextSearchFile saveLGFullTextSearchFile(List<DBContents> list, Long userId, LGFullTextSearchFile searchFile) throws Exception {
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
344 // save as csv and html file in filesystem, and records in db `FullTextSearchFile
49
7c2e1b14b77d new: load existing full text searching result into searching table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 48
diff changeset
345 // List<DBContents> list is the filteredList of searching result with isRemoved field
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
346
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
347 Date date = new Date();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
348
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
349 //Saving into DB
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
350 //##################################
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
351 Session session = HibernateUtil.getSessionFactory().openSession();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
352 Transaction tx = null;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
353 try{
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
354 tx = session.beginTransaction();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
355
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
356 DBService.saveDBEntry0(session, searchFile, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
357
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
358 //Saving physical file in the operating system
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
359 FileManager.saveFullTextSearchFileAsCsv(searchFile, userId, list); // save csv file to LGMap's datasets folder
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
360 FileManager.saveFullTextSearchFileAsHtml(searchFile, userId, list); // save html file to LGMap's datasets folder
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
361
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
362 tx.commit();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
363 }catch (Exception e) {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
364 if (tx!=null) tx.rollback();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
365
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
366 e.printStackTrace();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
367
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
368 throw e;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
369 }finally {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
370 session.close();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
371 }
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
372 //##################################
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
373
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
374 return searchFile;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
375 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
376
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
377 public LGFullTextSearchFile getFullTextSearchFile(Long fileId) {
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
378
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
379 LGFullTextSearchFile file = getFullTextSearchFileMap().getValuesByOwnKey(fileId);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
380
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
381 return file;
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
382 }
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
383
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
384 /* --- end full text search --- */
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
385
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
386 /* --- topic --- */
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
387
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
388 public List<LGTopic> getTopics(Long userId){
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
389 List<LGTopic> list = new ArrayList<LGTopic>();
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
390 for(LGTopic topic : getTopicMap().values()){
48
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
391 /*
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
392 if(topic.hasContributor(userId)){
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
393 list.add(topic);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
394 }
48
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
395 */
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
396
48
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
397 // add topic into list anyway, without checking the contributor role.
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
398 list.add(topic);
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
399 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
400
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
401 return list;
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
402 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
403
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
404 public LGTopic getTopic(Long topicId){
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
405 return getTopicMap().getValuesByOwnKey(topicId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
406 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
407
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
408
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
409 public void deleteTopic(LGTopic topic){
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
410
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
411 int modifiedRelation = DBService.deleteTopicFromDB(topic.getId());
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
412 getTopicMap().remove(topic.getKey());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
413
55
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
414 logger.info("removing " + modifiedRelation + " records in TopicSectionRelation and TopicTagRelation table for the topic " + topic.toString());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
415
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
416 this.setTopicSectionRelationMap(null); // clear topicSectionRelationMap cache
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
417
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
418 }
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
419
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
420 public void createTopic(String nameEn, String nameCh,String namePinyin, String description, Long userId) {
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
421
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
422 Date date = new Date();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
423
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
424 LGTopic topic = new LGTopic();
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
425 topic.setNameEn(nameEn);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
426 topic.setNameCh(nameCh);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
427 topic.setNamePinyin(namePinyin);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
428 topic.setDescription(description);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
429 topic.setUserId(userId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
430 topic.setContributors("[" + userId.toString() + "]");
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
431
55
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
432 // auto-generating a tag for the topic: could be from nameEn replace space with '_'
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
433 String tag = new String();
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
434 tag = nameEn.replace(' ', '_');
95bf4ac726e6 Topic synchronization with extraction-interface. new tables in LGService database
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 54
diff changeset
435 topic.setTag(tag);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
436
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
437 //Saving into DB
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
438 //##################################
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
439 // For Topic table
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
440 Session session = HibernateUtil.getSessionFactory().openSession();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
441 Transaction tx = null;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
442 try{
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
443 tx = session.beginTransaction();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
444
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
445 DBService.saveDBEntry0(session, topic, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
446
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
447 // For Taglist table
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
448 // create record, which is the topic tag, in taglist table,
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
449 // with the taglis.name=nameCh, the taglist.tag=tag, the taglist.color=the defualt topic tag color, which is rgb(255,0,174)
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
450
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
451 LGTaglist taglist = new LGTaglist();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
452 taglist.setName(nameCh);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
453
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
454 // tag to lowercase only!! bcuz it will be used as topic tag in Extraction-interface, and it'll be a tag in HTML which is case-insensitive
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
455 taglist.setTag(tag.toLowerCase());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
456
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
457 taglist.setColor("rgb(255, 0, 174)");
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
458
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
459 DBService.saveDBEntry0(session, taglist, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
460
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
461 logger.debug("new topic tag id=" + taglist.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
462
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
463 // For TopicTagRelation table
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
464 // link the relation between the new topic and its corresponding tag
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
465 LGTopicTagRelation relation = new LGTopicTagRelation();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
466 relation.setTagId(taglist.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
467 relation.setTopicId(topic.getId());
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
468
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
469 DBService.saveDBEntry0(session, relation, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
470
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
471 tx.commit();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
472
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
473 }catch (Exception e) {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
474 if (tx!=null) tx.rollback();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
475
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
476 e.printStackTrace();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
477
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
478 throw e;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
479 }finally {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
480 session.close();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
481 };
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
482 //##################################
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
483
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
484 }
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
485
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
486 public void updateTopic(LGTopic topic) throws Exception {
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
487 if(!topic.isPersistent()){
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
488 throw new Exception("Trying to update a topic that it is not persistent!");
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
489 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
490
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
491 Date date = new Date();
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
492 DBService.saveDBEntry(topic, date);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
493 this.getTopicMap().put(topic.getKey(), topic);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
494
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
495 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
496
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
497
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
498
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
499 public List<DBSection> getAllSectionsInTopic(Long topicId) throws SQLException{
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
500
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
501 List<LGTopicSectionRelation> topicSectionRelationList = getTopicSectionRelationMap().getValuesByAKey(topicId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
502
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
503 // get sections from topicSecionRelation list
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
504 List<DBSection> list = new ArrayList<DBSection>();
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
505 for (LGTopicSectionRelation aRelation : topicSectionRelationList) {
43
9dbbbfd474f4 new: 1.existing topic in search result. 2.difference-set of book for topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 41
diff changeset
506 //logger.debug(aRelation.getInfo() );
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
507
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
508 DBSection section = DBService.getSectionWithContent(aRelation.getSectionId());
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
509 list.add(section);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
510
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
511 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
512
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
513
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
514 Collections.sort(list);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
515 Collections.reverse(list);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
516 return list;
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
517 }
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
518
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
519
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
520
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
521
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
522 public void deleteTopicSectionRelation(Long topicId, String bookId) throws Exception{
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
523 // delete record with topicId, bookId in topicSectionRelation
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
524 // this means the sectionId = 0, there is no corresponding section in the book for this topic
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
525
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
526 // TODO
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
527
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
528 }
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
529
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
530 public void deleteTopicSectionRelation(Long topicId, Long sectionId) throws Exception{
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
531 if (sectionId == 0) {
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
532 throw new Exception("sectionId cannot be 0");
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
533 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
534
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
535 DuplexKey<Long, Long> key = new DuplexKey<Long, Long>(topicId, sectionId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
536 LGTopicSectionRelation topicSectionRelation = this.getTopicSectionRelationMap().get(key);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
537
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
538 LGTopic topic = getTopic(topicId);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
539
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
540 if(topic == null){
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
541 throw new Exception("There is no topic of " + topicSectionRelation);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
542 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
543
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
544 //deleting topicSectionRelation from DB and cache
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
545 int modifiedRelation = DBService.deleteTopicSectionRelationFromDB(topicSectionRelation.getId());
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
546 getTopicSectionRelationMap().remove(topicSectionRelation.getKey());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
547
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
548 logger.info(modifiedRelation + " items deleted by removing topicSectionRelation " + topicSectionRelation.toString());
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
549
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
550
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
551 }
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
552
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
553 public String updateTopicSectionRelation(Long sectionId, Long topicId) throws Exception {
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
554 DuplexKey<Long, Long> key = new DuplexKey<Long, Long>(topicId, sectionId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
555 LGTopicSectionRelation topicSectionRelation = this.getTopicSectionRelationMap().get(key);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
556
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
557 if (topicSectionRelation != null) {
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
558 // the relation already existed
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
559 // would this possibly need any modification to the existing record in the topicSectionRelation table?
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
560
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
561 return "updated";
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
562
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
563 } else {
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
564 createTopicSectionRelation(sectionId, topicId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
565
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
566 return "added";
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
567 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
568
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
569
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
570
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
571 }
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
572
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
573
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
574 public void createTopicSectionRelation(Long sectionId, Long topicId) throws Exception {
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
575
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
576 Date date = new Date();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
577
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
578 LGTopicSectionRelation topicSectionRelation = new LGTopicSectionRelation();
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
579 topicSectionRelation.setTopicId(topicId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
580 topicSectionRelation.setSectionId(sectionId);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
581
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
582 DBService.getInstance();
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
583 DBSection section = DBService.getSectionWithContent(sectionId);
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
584 topicSectionRelation.setBookId(section.getBookId());
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
585
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
586 //Saving into DB
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
587 //##################################
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
588 // For Topic table
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
589 Session session = HibernateUtil.getSessionFactory().openSession();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
590 Transaction tx = null;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
591 try{
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
592 tx = session.beginTransaction();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
593 DBService.saveDBEntry0(session, topicSectionRelation, date);
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
594 tx.commit();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
595 }catch (Exception e) {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
596 if (tx!=null) tx.rollback();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
597 e.printStackTrace();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
598 throw e;
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
599 }finally {
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
600 session.close();
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
601 }
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
602
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
603 // update cache
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
604 this.loadTopicSectionRelations();
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
605
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
606 }
39
37840afb7b80 new: full text search
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 38
diff changeset
607
48
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
608 public Integer getNumberOfSectionInTopic(Long topicId) {
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
609 List<LGTopicSectionRelation> topicSectionRelationList = getTopicSectionRelationMap().getValuesByAKey(topicId);
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
610
48
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
611 return topicSectionRelationList.size();
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
612 }
13555aff1f88 new: multiple full text searching. topics and tasks improvement.
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 43
diff changeset
613
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
614
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
615
41
ba9515f22897 new: topic management and adding sections from searching result into topic
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 40
diff changeset
616 /* --- end topic --- */
88
f4242db6206b Refactoring : replace getCurrentSession with openSession for nested transaction exception
Calvin Yeh <cyeh@mpipw-berlin.mpg.com>
parents: 68
diff changeset
617
0
3e62083dbcbf First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
"jurzua <jurzua@mpiwg-berlin.mpg.de>"
parents:
diff changeset
618 }