Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KS-4605 | [Forum] Fix bug EDIT PROPERTY. Item already exists when runs q... #137

Open
wants to merge 1 commit into
base: stable/2.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class ForumPageList extends JCRPageList {

private SessionManager sessionManager;

private NodeIterator iter_ = null;

private List listValue_ = null;

public ForumPageList(int pageSize, int size) {
Expand All @@ -55,19 +53,17 @@ public ForumPageList(NodeIterator iter, int pageSize, String value, boolean isQu
super(pageSize);
value_ = value;
isQuery_ = isQuery;

this.sessionManager = ForumServiceUtils.getSessionManager();
try {
if (iter == null) {
sessionManager.openSession();
iter = setQuery(isQuery_, value_);
iter_ = iter;
}
if (iter != null) {
setAvailablePage((int) iter.getSize());
}
iter = null;
} finally {
// sessionManager.closeSession();
this.sessionManager.closeSession();
}
}

Expand All @@ -84,15 +80,13 @@ public ForumPageList(List listResult) {

@SuppressWarnings("unchecked")
protected void populateCurrentPage(int page) throws Exception {
if (iter_ == null) {
iter_ = setQuery(isQuery_, value_);
setAvailablePage((int) iter_.getSize());
if (page == 0)
currentPage_ = 0; // nasty trick for getAll()
else
checkAndSetPage(page);
page = currentPage_;
}
NodeIterator iter = setQuery(isQuery_, value_);
setAvailablePage((int) iter.getSize());
if (page == 0)
currentPage_ = 0; // nasty trick for getAll()
else
checkAndSetPage(page);
page = currentPage_;
Node currentNode;
long pageSize = 0;
if (page > 0) {
Expand All @@ -102,16 +96,16 @@ protected void populateCurrentPage(int page) throws Exception {
position = 0;
else {
position = (page - 1) * pageSize;
iter_.skip(position);
iter.skip(position);
}
} else {
pageSize = iter_.getSize();
pageSize = iter.getSize();
}

currentListPage_ = new ArrayList<Object>();
for (int i = 0; i < pageSize; i++) {
if (iter_.hasNext()) {
currentNode = iter_.nextNode();
if (iter.hasNext()) {
currentNode = iter.nextNode();
if (currentNode.isNodeType("exo:post")) {
currentListPage_.add(getPost(currentNode));
} else if (currentNode.isNodeType(Utils.TYPE_TOPIC)) {
Expand All @@ -125,7 +119,7 @@ protected void populateCurrentPage(int page) throws Exception {
break;
}
}
iter_ = null;
iter = null;
if (sessionManager.getCurrentSession() != null && sessionManager.getCurrentSession().isLive()) {
sessionManager.closeSession();
}
Expand All @@ -134,12 +128,9 @@ protected void populateCurrentPage(int page) throws Exception {
@SuppressWarnings("unchecked")
protected void populateCurrentPage(String valueString) throws Exception {
NodeIterator nodeIterator = setQuery(isQuery_, value_);
if (iter_ == null) {
iter_ = setQuery(isQuery_, value_);
}
int pos = 0;
for (int i = 0; i < nodeIterator.getSize(); i++) {
if (getUserProfile(nodeIterator.nextNode()).getUserId().equals(valueString)) {
if (nodeIterator.nextNode().getName().equals(valueString)) {
pos = i + 1;
break;
}
Expand All @@ -154,6 +145,7 @@ protected void populateCurrentPage(String valueString) throws Exception {
page = page + 1;
}
}
NodeIterator iter_ = setQuery(isQuery_, value_);
this.pageSelected = page;
iter_.skip((page - 1) * pageSize);
currentListPage_ = new ArrayList<Object>();
Expand Down Expand Up @@ -200,7 +192,7 @@ protected void populateCurrentPageSearch(int page, List list, boolean isWatch, b
}

private NodeIterator setQuery(boolean isQuery, String value) throws Exception {
NodeIterator iter;
NodeIterator iter = null;
Session session = sessionManager.getCurrentSession();
if (session == null || !session.isLive()) {
sessionManager.openSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
public class JCRDataStorage implements DataStorage, ForumNodeTypes {

private static final Log log = ExoLogger.getLogger(JCRDataStorage.class);

private static final ThreadLocal<Node> nodeThreadLocal = new ThreadLocal<Node>();

private Map<String, String> serverConfig = new HashMap<String, String>();

Expand Down Expand Up @@ -2804,11 +2806,13 @@ public JCRPageList getPostForSplitTopic(String topicPath) throws Exception {
}

public JCRPageList getPosts(String categoryId, String forumId, String topicId, String isApproved, String isHidden, String strQuery, String userLogin) throws Exception {
SessionProvider sProvider = CommonUtils.createSystemProvider();
try {
Node topicNode = getCategoryHome(sProvider).getNode(categoryId + "/" + forumId + "/" + topicId);
StringBuilder strBuilder = new StringBuilder(JCR_ROOT)
.append(topicNode.getPath()).append("//element(*,").append(EXO_POST).append(")");
StringBuilder strBuilder = new StringBuilder().append(JCR_ROOT).append("/")
.append(dataLocator.getForumCategoriesLocation()).append("/")
.append(categoryId).append("/")
.append(forumId).append("/")
.append(topicId)
.append("//element(*,").append(EXO_POST).append(")");
String isWaiting = strQuery.equals("true") || strQuery.equals("false") ? strQuery : "";
StringBuilder qr = Utils.getPathQuery(isApproved, isHidden, isWaiting, userLogin);
if (!Utils.isEmpty(strQuery) && Utils.isEmpty(isWaiting)) {
Expand Down Expand Up @@ -2994,6 +2998,7 @@ public void savePost(String categoryId, String forumId, String topicId, Post pos
try {
Node CategoryNode = getCategoryHome(sProvider).getNode(categoryId);
Node forumNode = CategoryNode.getNode(forumId);
nodeThreadLocal.set(forumNode);
Node topicNode = forumNode.getNode(topicId);
Node postNode;
Calendar calendar = getGreenwichMeanTime();
Expand Down Expand Up @@ -3183,7 +3188,11 @@ public void savePost(String categoryId, String forumId, String topicId, Post pos
}
postNode.setProperty(EXO_NUMBER_ATTACH, numberAttach);
if (isNew) {
forumNode.getSession().save();
try {
forumNode.getSession().save();
} catch (RepositoryException e) {
nodeThreadLocal.get().getSession().save();
}
} else {
forumNode.save();
}
Expand All @@ -3206,6 +3215,8 @@ public void savePost(String categoryId, String forumId, String topicId, Post pos
}
} catch (Exception e) {
log.error("Failed to save post" + post.getName(), e);
} finally {
nodeThreadLocal.set(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,22 +635,25 @@ public List<Post> getPostPageList() throws Exception {
} catch (Exception e) {
log.warn("Failed to find last read index for topic: " + e.getMessage(), e);
}
posts = pageList.getPage(pageSelect);
pageSelect = pageList.getCurrentPage();
pagePostRemember.put(topicId, pageSelect);
if (posts == null)
posts = new ArrayList<Post>();
List<String> userNames = new ArrayList<String>();
mapUserProfile.clear();
for (Post post : posts) {
if (!userNames.contains(post.getOwner()))
userNames.add(post.getOwner());
if (getUICheckBoxInput(post.getId()) != null) {
getUICheckBoxInput(post.getId()).setChecked(false);
} else {
addUIFormInput(new UICheckBoxInput(post.getId(), post.getId(), false));
}
this.IdLastPost = post.getId();
List<String> userNames = null;
synchronized (this) {
posts = pageList.getPage(pageSelect);
pageSelect = pageList.getCurrentPage();
pagePostRemember.put(topicId, pageSelect);
if (posts == null)
posts = new ArrayList<Post>();
userNames = new ArrayList<String>();
mapUserProfile.clear();
for (Post post : posts) {
if (!userNames.contains(post.getOwner()))
userNames.add(post.getOwner());
if (getUICheckBoxInput(post.getId()) != null) {
getUICheckBoxInput(post.getId()).setChecked(false);
} else {
addUIFormInput(new UICheckBoxInput(post.getId(), post.getId(), false));
}
this.IdLastPost = post.getId();
}
}
if (!lastPoistIdSave.equals(IdLastPost)) {
lastPoistIdSave = IdLastPost;
Expand All @@ -661,7 +664,7 @@ public List<Post> getPostPageList() throws Exception {
}
}
// updateUserProfiles
if (userNames.size() > 0) {
if (userNames != null && userNames.size() > 0) {
try {
List<UserProfile> profiles = getForumService().getQuickProfiles(userNames);
for (UserProfile profile : profiles) {
Expand Down