1
22
23 package com.liferay.portlet.messageboards.model.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.model.impl.CompanyImpl;
28 import com.liferay.portal.util.PortalUtil;
29 import com.liferay.portlet.messageboards.model.MBCategory;
30 import com.liferay.portlet.messageboards.model.MBMessage;
31 import com.liferay.portlet.messageboards.service.MBCategoryLocalServiceUtil;
32 import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
33 import com.liferay.portlet.messageboards.util.BBCodeUtil;
34 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
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() == CompanyImpl.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() == CompanyImpl.SYSTEM) {
96 return true;
97 }
98 else {
99 return false;
100 }
101 }
102
103 public double getPriority() throws PortalException, SystemException {
104 if (_priority == -1) {
105 _priority = MBThreadLocalServiceUtil.getThread(getThreadId()).
106 getPriority();
107 }
108 return _priority;
109 }
110
111 public void setPriority(double priority) {
112 _priority = priority;
113 }
114
115 public String getThreadAttachmentsDir() {
116 return "messageboards/" + getThreadId();
117 }
118
119 public String getAttachmentsDir() {
120 if (_attachmentDirs == null) {
121 _attachmentDirs = getThreadAttachmentsDir() + "/" + getMessageId();
122 }
123 return _attachmentDirs;
124 }
125
126 public void setAttachmentsDir(String attachmentsDir) {
127 _attachmentDirs = attachmentsDir;
128 }
129
130 public String getBody(boolean translated) {
131 if (translated) {
132 return BBCodeUtil.getHTML(getBody());
133 }
134 else {
135 return getBody();
136 }
137 }
138
139 public String[] getTagsEntries() throws PortalException, SystemException {
140 return TagsEntryLocalServiceUtil.getEntryNames(
141 MBMessage.class.getName(), getMessageId());
142 }
143
144 private static Log _log = LogFactory.getLog(MBMessageImpl.class);
145
146 private String _userUuid;
147 private double _priority = -1;
148 private String _attachmentDirs;
149
150 }