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