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.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portlet.imagegallery.model.IGImage;
020    import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
021    
022    import java.util.List;
023    
024    /**
025     * @author Raymond Augé
026     */
027    public class VerifyImageGallery extends VerifyProcess {
028    
029            protected void doVerify() throws Exception {
030                    List<IGImage> images = IGImageLocalServiceUtil.getNoAssetImages();
031    
032                    if (_log.isDebugEnabled()) {
033                            _log.debug("Processing " + images.size() + " images with no asset");
034                    }
035    
036                    for (IGImage image : images) {
037                            try {
038                                    IGImageLocalServiceUtil.updateAsset(
039                                            image.getUserId(), image, null, null, null);
040                            }
041                            catch (Exception e) {
042                                    if (_log.isWarnEnabled()) {
043                                            _log.warn(
044                                                    "Unable to update asset for image " +
045                                                            image.getImageId() + ": " + e.getMessage());
046                                    }
047                            }
048                    }
049    
050                    if (_log.isDebugEnabled()) {
051                            _log.debug("Assets verified for images");
052                    }
053            }
054    
055            private static Log _log = LogFactoryUtil.getLog(VerifyImageGallery.class);
056    
057    }