1
19
20 package com.liferay.portlet.messageboards.model.impl;
21
22 import com.liferay.documentlibrary.NoSuchDirectoryException;
23 import com.liferay.documentlibrary.service.DLServiceUtil;
24 import com.liferay.portal.PortalException;
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.log.Log;
27 import com.liferay.portal.kernel.log.LogFactoryUtil;
28 import com.liferay.portal.model.CompanyConstants;
29 import com.liferay.portal.util.PortalUtil;
30 import com.liferay.portlet.messageboards.model.MBCategory;
31 import com.liferay.portlet.messageboards.model.MBMessage;
32 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
33 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
34 import com.liferay.portlet.messageboards.util.BBCodeUtil;
35 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
36
37 import java.rmi.RemoteException;
38
39
45 public class MBMessageImpl extends MBMessageModelImpl implements MBMessage {
46
47 public static final long DEFAULT_PARENT_MESSAGE_ID = 0;
48
49 public MBMessageImpl() {
50 }
51
52 public String getUserUuid() throws SystemException {
53 return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
54 }
55
56 public void setUserUuid(String userUuid) {
57 _userUuid = userUuid;
58 }
59
60 public MBCategory getCategory() {
61 MBCategory category = null;
62
63 try {
64 if (getCategoryId() == CompanyConstants.SYSTEM) {
65 category = MBCategoryLocalServiceUtil.getSystemCategory();
66 }
67 else {
68 category = MBCategoryLocalServiceUtil.getCategory(
69 getCategoryId());
70 }
71 }
72 catch (Exception e) {
73 category = new MBCategoryImpl();
74
75 _log.error(e);
76 }
77
78 return category;
79 }
80
81 public boolean isRoot() {
82 if (getParentMessageId() == DEFAULT_PARENT_MESSAGE_ID) {
83 return true;
84 }
85 else {
86 return false;
87 }
88 }
89
90 public boolean isReply() {
91 return !isRoot();
92 }
93
94 public boolean isDiscussion() {
95 if (getCategoryId() == CompanyConstants.SYSTEM) {
96 return true;
97 }
98 else {
99 return false;
100 }
101 }
102
103 public String getBody(boolean translate) {
104 String body = null;
105
106 if (translate) {
107 body = BBCodeUtil.getHTML(this);
108 }
109 else {
110 body = getBody();
111 }
112
113 return body;
114 }
115
116 public String getThreadAttachmentsDir() {
117 return "messageboards/" + getThreadId();
118 }
119
120 public String getAttachmentsDir() {
121 if (_attachmentDirs == null) {
122 _attachmentDirs = getThreadAttachmentsDir() + "/" + getMessageId();
123 }
124
125 return _attachmentDirs;
126 }
127
128 public void setAttachmentsDir(String attachmentsDir) {
129 _attachmentDirs = attachmentsDir;
130 }
131
132 public String[] getAttachmentsFiles()
133 throws PortalException, SystemException {
134
135 String[] fileNames = new String[0];
136
137 try {
138 fileNames = DLServiceUtil.getFileNames(
139 getCompanyId(), CompanyConstants.SYSTEM, getAttachmentsDir());
140 }
141 catch (NoSuchDirectoryException nsde) {
142 }
143 catch (RemoteException re) {
144 _log.error(re);
145 }
146
147 return fileNames;
148 }
149
150 public double getPriority() throws PortalException, SystemException {
151 if (_priority == -1) {
152 _priority = MBThreadLocalServiceUtil.getThread(getThreadId()).
153 getPriority();
154 }
155
156 return _priority;
157 }
158
159 public void setPriority(double priority) {
160 _priority = priority;
161 }
162
163 public String[] getTagsEntries() throws SystemException {
164 return TagsEntryLocalServiceUtil.getEntryNames(
165 MBMessage.class.getName(), getMessageId());
166 }
167
168 private static Log _log = LogFactoryUtil.getLog(MBMessageImpl.class);
169
170 private String _userUuid;
171 private double _priority = -1;
172 private String _attachmentDirs;
173
174 }