001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.jsonwebservice.JSONWebService;
021 import com.liferay.portal.kernel.jsonwebservice.JSONWebServiceMode;
022 import com.liferay.portal.kernel.log.Log;
023 import com.liferay.portal.kernel.log.LogFactoryUtil;
024 import com.liferay.portal.kernel.messaging.DestinationNames;
025 import com.liferay.portal.kernel.messaging.Message;
026 import com.liferay.portal.kernel.messaging.sender.DirectSynchronousMessageSender;
027 import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
028 import com.liferay.portal.kernel.util.PropsKeys;
029 import com.liferay.portal.kernel.util.ReleaseInfo;
030 import com.liferay.portal.model.ClassName;
031 import com.liferay.portal.service.PortalService;
032 import com.liferay.portal.service.base.PortalServiceBaseImpl;
033 import com.liferay.portal.util.PrefsPropsUtil;
034 import com.liferay.portal.util.PropsValues;
035
036
039 @JSONWebService(mode = JSONWebServiceMode.MANUAL)
040 public class PortalServiceImpl extends PortalServiceBaseImpl {
041
042 public String getAutoDeployDirectory() throws SystemException {
043 return PrefsPropsUtil.getString(
044 PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
045 PropsValues.AUTO_DEPLOY_DEPLOY_DIR);
046 }
047
048 @JSONWebService
049 public int getBuildNumber() {
050 return ReleaseInfo.getBuildNumber();
051 }
052
053 public void testAddClassName_Rollback(String classNameValue)
054 throws SystemException {
055
056 addClassName(classNameValue);
057
058 throw new SystemException();
059 }
060
061 public void testAddClassName_Success(String classNameValue)
062 throws SystemException {
063
064 addClassName(classNameValue);
065 }
066
067 public void testAddClassNameAndTestTransactionPortletBar_PortalRollback(
068 String transactionPortletBarText)
069 throws SystemException {
070
071 addClassName(PortalService.class.getName());
072
073 addTransactionPortletBar(transactionPortletBarText, false);
074
075 throw new SystemException();
076 }
077
078 public void testAddClassNameAndTestTransactionPortletBar_PortletRollback(
079 String transactionPortletBarText)
080 throws SystemException {
081
082 addClassName(PortalService.class.getName());
083
084 addTransactionPortletBar(transactionPortletBarText, true);
085 }
086
087 public void testAddClassNameAndTestTransactionPortletBar_Success(
088 String transactionPortletBarText)
089 throws SystemException {
090
091 addClassName(PortalService.class.getName());
092
093 addTransactionPortletBar(transactionPortletBarText, false);
094 }
095
096 public void testCounterIncrement_Rollback() throws SystemException {
097 int counterIncrement = PropsValues.COUNTER_INCREMENT;
098
099 for (int i = 0; i < counterIncrement * 2; i++) {
100 counterLocalService.increment();
101 }
102
103 throw new SystemException();
104 }
105
106 public void testDeleteClassName() throws PortalException, SystemException {
107 classNamePersistence.removeByValue(PortalService.class.getName());
108 }
109
110 public int testGetBuildNumber() {
111 return portalService.getBuildNumber();
112 }
113
114 public void testGetUserId() {
115 long userId = 0;
116
117 try {
118 userId = getUserId();
119 }
120 catch (Exception e) {
121 _log.error(e, e);
122 }
123
124 if (_log.isInfoEnabled()) {
125 _log.info("User id " + userId);
126 }
127 }
128
129 public boolean testHasClassName() throws SystemException {
130 int count = classNamePersistence.countByValue(
131 PortalService.class.getName());
132
133 if (count > 0) {
134 return true;
135 }
136 else {
137 return false;
138 }
139 }
140
141 protected void addClassName(String classNameValue) throws SystemException {
142 long classNameId = counterLocalService.increment();
143
144 ClassName className = classNamePersistence.create(classNameId);
145
146 className.setValue(classNameValue);
147
148 classNamePersistence.update(className);
149 }
150
151 protected void addTransactionPortletBar(
152 String transactionPortletBarText, boolean rollback)
153 throws SystemException {
154
155 try {
156 Message message = new Message();
157
158 message.put("rollback", rollback);
159 message.put("text", transactionPortletBarText);
160
161 SynchronousMessageSender synchronousMessageSender =
162 (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
163 DirectSynchronousMessageSender.class.getName());
164
165 synchronousMessageSender.send(
166 DestinationNames.TEST_TRANSACTION, message);
167 }
168 catch (Exception e) {
169 throw new SystemException(e);
170 }
171 }
172
173 private static Log _log = LogFactoryUtil.getLog(PortalServiceImpl.class);
174
175 }