1
22
23 package com.liferay.portlet.messageboards.model.impl;
24
25 import com.liferay.documentlibrary.NoSuchDirectoryException;
26 import com.liferay.documentlibrary.service.DLServiceUtil;
27 import com.liferay.portal.PortalException;
28 import com.liferay.portal.SystemException;
29 import com.liferay.portal.model.CompanyConstants;
30 import com.liferay.portal.util.PortalUtil;
31 import com.liferay.portlet.messageboards.model.MBCategory;
32 import com.liferay.portlet.messageboards.model.MBMessage;
33 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
34 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
35 import com.liferay.portlet.messageboards.util.BBCodeUtil;
36 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
37
38 import java.rmi.RemoteException;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43
49 public class MBMessageImpl extends MBMessageModelImpl implements MBMessage {
50
51 public static final long DEFAULT_PARENT_MESSAGE_ID = 0;
52
53 public MBMessageImpl() {
54 }
55
56 public String getUserUuid() throws SystemException {
57 return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
58 }
59
60 public void setUserUuid(String userUuid) {
61 _userUuid = userUuid;
62 }
63
64 public MBCategory getCategory() {
65 MBCategory category = null;
66
67 try {
68 if (getCategoryId() == CompanyConstants.SYSTEM) {
69 category = MBCategoryLocalServiceUtil.getSystemCategory();
70 }
71 else {
72 category = MBCategoryLocalServiceUtil.getCategory(
73 getCategoryId());
74 }
75 }
76 catch (Exception e) {
77 category = new MBCategoryImpl();
78
79 _log.error(e);
80 }
81
82 return category;
83 }
84
85 public boolean isRoot() {
86 if (getParentMessageId() == DEFAULT_PARENT_MESSAGE_ID) {
87 return true;
88 }
89 else {
90 return false;
91 }
92 }
93
94 public boolean isReply() {
95 return !isRoot();
96 }
97
98 public boolean isDiscussion() {
99 if (getCategoryId() == CompanyConstants.SYSTEM) {
100 return true;
101 }
102 else {
103 return false;
104 }
105 }
106
107 public String getBody(boolean translated) {
108 if (translated) {
109 return BBCodeUtil.getHTML(getBody());
110 }
111 else {
112 return getBody();
113 }
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 PortalException, SystemException {
164 return TagsEntryLocalServiceUtil.getEntryNames(
165 MBMessage.class.getName(), getMessageId());
166 }
167
168 private static Log _log = LogFactory.getLog(MBMessageImpl.class);
169
170 private String _userUuid;
171 private double _priority = -1;
172 private String _attachmentDirs;
173
174 }