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()
107 throws PortalException, SystemException {
108
109 classNamePersistence.removeByValue(PortalService.class.getName());
110 }
111
112 public void testGetUserId() {
113 long userId = 0;
114
115 try {
116 userId = getUserId();
117 }
118 catch (Exception e) {
119 e.printStackTrace();
120 }
121
122 if (_log.isInfoEnabled()) {
123 _log.info("User id " + userId);
124 }
125 }
126
127 public boolean testHasClassName() throws SystemException {
128 int count = classNamePersistence.countByValue(
129 PortalService.class.getName());
130
131 if (count > 0) {
132 return true;
133 }
134 else {
135 return false;
136 }
137 }
138
139 protected void addClassName(String classNameValue) throws SystemException {
140 long classNameId = counterLocalService.increment();
141
142 ClassName className = classNamePersistence.create(classNameId);
143
144 className.setValue(classNameValue);
145
146 classNamePersistence.update(className, false);
147 }
148
149 protected void addTransactionPortletBar(
150 String transactionPortletBarText, boolean rollback)
151 throws SystemException {
152
153 try {
154 Message message = new Message();
155
156 message.put("rollback", rollback);
157 message.put("text", transactionPortletBarText);
158
159 SynchronousMessageSender synchronousMessageSender =
160 (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
161 DirectSynchronousMessageSender.class.getName());
162
163 synchronousMessageSender.send(
164 DestinationNames.TEST_TRANSACTION, message);
165 }
166 catch (Exception e) {
167 throw new SystemException(e);
168 }
169 }
170
171 private static Log _log = LogFactoryUtil.getLog(PortalServiceImpl.class);
172
173 }