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.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            @Override
030            protected void doVerify() throws Exception {
031    
032                    // Resource
033    
034                    long latestResourceId = ResourceLocalServiceUtil.getLatestResourceId();
035    
036                    long counterResourceId = CounterLocalServiceUtil.increment(
037                            Resource.class.getName());
038    
039                    if (latestResourceId > counterResourceId - 1) {
040                            CounterLocalServiceUtil.reset(
041                                    Resource.class.getName(), latestResourceId);
042                    }
043    
044                    // Permission
045    
046                    long latestPermissionId =
047                            PermissionLocalServiceUtil.getLatestPermissionId();
048    
049                    long counterPermissionId = CounterLocalServiceUtil.increment(
050                            Permission.class.getName());
051    
052                    if (latestPermissionId > counterPermissionId - 1) {
053                            CounterLocalServiceUtil.reset(
054                                    Permission.class.getName(), latestPermissionId);
055                    }
056            }
057    
058    }