001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.kernel.messaging.DestinationNames;
023    import com.liferay.portal.kernel.messaging.Message;
024    import com.liferay.portal.kernel.messaging.sender.DirectSynchronousMessageSender;
025    import com.liferay.portal.kernel.messaging.sender.SynchronousMessageSender;
026    import com.liferay.portal.kernel.util.PropsKeys;
027    import com.liferay.portal.kernel.util.ReleaseInfo;
028    import com.liferay.portal.model.ClassName;
029    import com.liferay.portal.service.PortalService;
030    import com.liferay.portal.service.base.PortalServiceBaseImpl;
031    import com.liferay.portal.util.PrefsPropsUtil;
032    import com.liferay.portal.util.PropsValues;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     */
037    public class PortalServiceImpl extends PortalServiceBaseImpl {
038    
039            public String getAutoDeployDirectory() throws SystemException {
040                    return PrefsPropsUtil.getString(
041                            PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
042                            PropsValues.AUTO_DEPLOY_DEPLOY_DIR);
043            }
044    
045            public int getBuildNumber() {
046                    return ReleaseInfo.getBuildNumber();
047            }
048    
049            public void testAddClassName_Rollback(String classNameValue)
050                    throws SystemException {
051    
052                    addClassName(classNameValue);
053    
054                    throw new SystemException();
055            }
056    
057            public void testAddClassName_Success(String classNameValue)
058                    throws SystemException {
059    
060                    addClassName(classNameValue);
061            }
062    
063            public void testAddClassNameAndTestTransactionPortletBar_PortalRollback(
064                            String transactionPortletBarText)
065                    throws SystemException {
066    
067                    addClassName(PortalService.class.getName());
068    
069                    addTransactionPortletBar(transactionPortletBarText, false);
070    
071                    throw new SystemException();
072            }
073    
074            public void testAddClassNameAndTestTransactionPortletBar_PortletRollback(
075                            String transactionPortletBarText)
076                    throws SystemException {
077    
078                    addClassName(PortalService.class.getName());
079    
080                    addTransactionPortletBar(transactionPortletBarText, true);
081            }
082    
083            public void testAddClassNameAndTestTransactionPortletBar_Success(
084                            String transactionPortletBarText)
085                    throws SystemException {
086    
087                    addClassName(PortalService.class.getName());
088    
089                    addTransactionPortletBar(transactionPortletBarText, false);
090            }
091    
092            public void testCounterIncrement_Rollback() throws SystemException {
093                    int counterIncrement = PropsValues.COUNTER_INCREMENT;
094    
095                    for (int i = 0; i < counterIncrement * 2; i++) {
096                            counterLocalService.increment();
097                    }
098    
099                    throw new SystemException();
100            }
101    
102            public void testDeleteClassName()
103                    throws PortalException, SystemException {
104    
105                    classNamePersistence.removeByValue(PortalService.class.getName());
106            }
107    
108            public void testGetUserId() {
109                    long userId = 0;
110    
111                    try {
112                            userId = getUserId();
113                    }
114                    catch (Exception e) {
115                            e.printStackTrace();
116                    }
117    
118                    if (_log.isInfoEnabled()) {
119                            _log.info("User id " + userId);
120                    }
121            }
122    
123            public boolean testHasClassName() throws SystemException {
124                    int count = classNamePersistence.countByValue(
125                            PortalService.class.getName());
126    
127                    if (count > 0) {
128                            return true;
129                    }
130                    else {
131                            return false;
132                    }
133            }
134    
135            protected void addClassName(String classNameValue) throws SystemException {
136                    long classNameId = counterLocalService.increment();
137    
138                    ClassName className = classNamePersistence.create(classNameId);
139    
140                    className.setValue(classNameValue);
141    
142                    classNamePersistence.update(className, false);
143            }
144    
145            protected void addTransactionPortletBar(
146                            String transactionPortletBarText, boolean rollback)
147                    throws SystemException {
148    
149                    try {
150                            Message message = new Message();
151    
152                            message.put("rollback", rollback);
153                            message.put("text", transactionPortletBarText);
154    
155                            SynchronousMessageSender synchronousMessageSender =
156                                    (SynchronousMessageSender)PortalBeanLocatorUtil.locate(
157                                            DirectSynchronousMessageSender.class.getName());
158    
159                            synchronousMessageSender.send(
160                                    DestinationNames.TEST_TRANSACTION, message);
161                    }
162                    catch (Exception e) {
163                            throw new SystemException(e);
164                    }
165            }
166    
167            private static Log _log = LogFactoryUtil.getLog(PortalServiceImpl.class);
168    
169    }