001
014
015 package com.liferay.portlet.messageboards.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.repository.model.Folder;
020 import com.liferay.portal.model.Lock;
021 import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
022 import com.liferay.portal.service.LockLocalServiceUtil;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
026 import com.liferay.portlet.messageboards.model.MBCategory;
027 import com.liferay.portlet.messageboards.model.MBMessage;
028 import com.liferay.portlet.messageboards.model.MBThread;
029 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
030 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
031
032
036 public class MBThreadImpl extends MBThreadBaseImpl {
037
038 public MBThreadImpl() {
039 }
040
041 public long getAttachmentsFolderId()
042 throws PortalException, SystemException {
043
044 ServiceContext serviceContext = new ServiceContext();
045
046 serviceContext.setAddGroupPermissions(true);
047 serviceContext.setAddGuestPermissions(true);
048
049 long repositoryId = PortletFileRepositoryUtil.getPortletRepositoryId(
050 getGroupId(), PortletKeys.MESSAGE_BOARDS, serviceContext);
051
052 MBMessage message = MBMessageLocalServiceUtil.getMessage(
053 getRootMessageId());
054
055 Folder folder = PortletFileRepositoryUtil.getPortletFolder(
056 message.getUserId(), repositoryId,
057 DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
058 String.valueOf(getThreadId()), serviceContext);
059
060 return folder.getFolderId();
061 }
062
063 public Lock getLock() {
064 try {
065 return LockLocalServiceUtil.getLock(
066 MBThread.class.getName(), getThreadId());
067 }
068 catch (Exception e) {
069 }
070
071 return null;
072 }
073
074 public MBCategory getTrashContainer() {
075 try {
076 MBCategory category = MBCategoryLocalServiceUtil.getCategory(
077 getCategoryId());
078
079 if (category.isInTrash()) {
080 return category;
081 }
082
083 return category.getTrashContainer();
084 }
085 catch (Exception e) {
086 return null;
087 }
088 }
089
090 public boolean hasLock(long userId) {
091 try {
092 return LockLocalServiceUtil.hasLock(
093 userId, MBThread.class.getName(), getThreadId());
094 }
095 catch (Exception e) {
096 }
097
098 return false;
099 }
100
101 public boolean isInTrashContainer() {
102 if (getTrashContainer() != null) {
103 return true;
104 }
105 else {
106 return false;
107 }
108 }
109
110 public boolean isLocked() {
111 try {
112 if (isInTrash() || isInTrashContainer()) {
113 return true;
114 }
115
116 return LockLocalServiceUtil.isLocked(
117 MBThread.class.getName(), getThreadId());
118 }
119 catch (Exception e) {
120 }
121
122 return false;
123 }
124
125 }