001    /**
002     * Copyright (c) 2000-2012 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.portlet.documentlibrary.util;
016    
017    import com.liferay.portal.kernel.lock.BaseLockListener;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.util.PropsValues;
023    import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
024    import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
025    
026    /**
027     * @author Alexander Chow
028     */
029    public class DLFileEntryLockListener extends BaseLockListener {
030    
031            public String getClassName() {
032                    return DLFileEntryConstants.getClassName();
033            }
034    
035            @Override
036            public void onAfterExpire(String key) {
037                    long fileEntryId = GetterUtil.getLong(key);
038    
039                    try {
040                            if (PropsValues.DL_FILE_ENTRY_LOCK_POLICY == 1) {
041                                    DLFileEntryServiceUtil.checkInFileEntry(
042                                            fileEntryId, true, "Automatic timeout checkin",
043                                            new ServiceContext());
044    
045                                    if (_log.isDebugEnabled()) {
046                                            _log.debug("Lock expired and checked in " + fileEntryId);
047                                    }
048                            }
049                            else {
050                                    DLFileEntryServiceUtil.cancelCheckOut(fileEntryId);
051    
052                                    if (_log.isDebugEnabled()) {
053                                            _log.debug(
054                                                    "Lock expired and canceled check out of " +
055                                                            fileEntryId);
056                                    }
057                            }
058                    }
059                    catch (Exception e) {
060                            _log.error(e, e);
061                    }
062            }
063    
064            private static Log _log = LogFactoryUtil.getLog(
065                    DLFileEntryLockListener.class);
066    
067    }