001    /**
002     * Copyright (c) 2000-2013 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            @Override
032            public String getClassName() {
033                    return DLFileEntryConstants.getClassName();
034            }
035    
036            @Override
037            public void onAfterExpire(String key) {
038                    long fileEntryId = GetterUtil.getLong(key);
039    
040                    try {
041                            if (PropsValues.DL_FILE_ENTRY_LOCK_POLICY == 1) {
042                                    DLFileEntryServiceUtil.checkInFileEntry(
043                                            fileEntryId, true, "Automatic timeout checkin",
044                                            new ServiceContext());
045    
046                                    if (_log.isDebugEnabled()) {
047                                            _log.debug("Lock expired and checked in " + fileEntryId);
048                                    }
049                            }
050                            else {
051                                    DLFileEntryServiceUtil.cancelCheckOut(fileEntryId);
052    
053                                    if (_log.isDebugEnabled()) {
054                                            _log.debug(
055                                                    "Lock expired and canceled check out of " +
056                                                            fileEntryId);
057                                    }
058                            }
059                    }
060                    catch (Exception e) {
061                            _log.error(e, e);
062                    }
063            }
064    
065            private static Log _log = LogFactoryUtil.getLog(
066                    DLFileEntryLockListener.class);
067    
068    }