/** * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.ese.ils.beta.service.impl; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.faces.model.SelectItem; import com.ese.ils.beta.model.Favorite; import com.ese.ils.beta.service.base.FavoriteLocalServiceBaseImpl; import com.ese.ils.beta.util.DeComposer; import com.liferay.counter.service.CounterLocalServiceUtil; import com.liferay.portal.kernel.exception.SystemException; /** * The implementation of the favorite local service. * * <p> * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.ese.ils.beta.service.FavoriteLocalService} interface. * * <p> * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM. * </p> * * @author edik * @see com.ese.ils.beta.service.base.FavoriteLocalServiceBaseImpl * @see com.ese.ils.beta.service.FavoriteLocalServiceUtil */ public class FavoriteLocalServiceImpl extends FavoriteLocalServiceBaseImpl { public List<Favorite> fetchModuleFavorites(long userId, long moduleId){ List<Favorite> favoriteList = new ArrayList<Favorite>(); try{ favoriteList = favoritePersistence.findByUserModule(userId, moduleId); } catch (Exception e){ e.printStackTrace(); } return favoriteList; } public boolean addFavorite(long slideId, long moduleId, long userId){ long favoriteId; boolean status = false; try { favoriteId = CounterLocalServiceUtil.increment(Favorite.class.getName()); Favorite favorite = favoritePersistence.create(favoriteId); favorite.setSlideId(slideId); favorite.setModuleId(moduleId); favorite.setUserId(userId); favoritePersistence.update(favorite, false); status=true; } catch (SystemException e) { e.printStackTrace(); } return status; } public int countFavBySlideId(long slideId) { int countFavsBySlide = -1; try { countFavsBySlide = favoritePersistence.countByBySlide(slideId); } catch (SystemException e) { e.printStackTrace(); } return countFavsBySlide; } public boolean isFavorite(long slideId,long userId){ try { if(favoritePersistence.findByUserAndSlide(userId, slideId).size()==1){ return true; } } catch (SystemException e) { e.printStackTrace(); } return false; } }