001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }