001    /**
002     * Copyright (c) 2000-2011 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.portal.verify;
016    
017    import com.liferay.counter.service.CounterLocalServiceUtil;
018    import com.liferay.portal.model.Permission;
019    import com.liferay.portal.model.Resource;
020    import com.liferay.portal.service.PermissionLocalServiceUtil;
021    import com.liferay.portal.service.ResourceLocalServiceUtil;
022    
023    /**
024     * @author Alexander Chow
025     * @author Brian Wing Shun Chan
026     */
027    public class VerifyCounter extends VerifyProcess {
028    
029            protected void doVerify() throws Exception {
030    
031                    // Resource
032    
033                    long latestResourceId = ResourceLocalServiceUtil.getLatestResourceId();
034    
035                    long counterResourceId = CounterLocalServiceUtil.increment(
036                            Resource.class.getName());
037    
038                    if (latestResourceId > counterResourceId - 1) {
039                            CounterLocalServiceUtil.reset(
040                                    Resource.class.getName(), latestResourceId);
041                    }
042    
043                    // Permission
044    
045                    long latestPermissionId =
046                            PermissionLocalServiceUtil.getLatestPermissionId();
047    
048                    long counterPermissionId = CounterLocalServiceUtil.increment(
049                            Permission.class.getName());
050    
051                    if (latestPermissionId > counterPermissionId - 1) {
052                            CounterLocalServiceUtil.reset(
053                                    Permission.class.getName(), latestPermissionId);
054                    }
055            }
056    
057    }