001    /**
002     * Copyright (c) 2000-2012 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            @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    }