001    /**
002     * Copyright (c) 2000-2013 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.portlet.polls.model.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.polls.model.PollsChoice;
021    import com.liferay.portlet.polls.model.PollsVote;
022    import com.liferay.portlet.polls.service.PollsChoiceLocalServiceUtil;
023    import com.liferay.portlet.polls.service.PollsVoteLocalServiceUtil;
024    
025    import java.util.Date;
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class PollsQuestionImpl extends PollsQuestionBaseImpl {
032    
033            public PollsQuestionImpl() {
034            }
035    
036            @Override
037            public List<PollsChoice> getChoices() throws SystemException {
038                    return PollsChoiceLocalServiceUtil.getChoices(getQuestionId());
039            }
040    
041            @Override
042            public List<PollsVote> getVotes() throws SystemException {
043                    return PollsVoteLocalServiceUtil.getQuestionVotes(
044                            getQuestionId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);
045            }
046    
047            @Override
048            public List<PollsVote> getVotes(int start, int end) throws SystemException {
049                    return PollsVoteLocalServiceUtil.getQuestionVotes(
050                            getQuestionId(), start, end);
051            }
052    
053            @Override
054            public int getVotesCount() throws SystemException {
055                    return PollsVoteLocalServiceUtil.getQuestionVotesCount(getQuestionId());
056            }
057    
058            @Override
059            public boolean isExpired() {
060                    Date expirationDate = getExpirationDate();
061    
062                    if ((expirationDate != null) && expirationDate.before(new Date())) {
063                            return true;
064                    }
065                    else {
066                            return false;
067                    }
068            }
069    
070            @Override
071            public boolean isExpired(
072                    ServiceContext serviceContext, Date defaultCreateDate) {
073    
074                    Date expirationDate = getExpirationDate();
075    
076                    if (expirationDate == null) {
077                            return false;
078                    }
079    
080                    Date createDate = serviceContext.getCreateDate(defaultCreateDate);
081    
082                    if (createDate.after(expirationDate)) {
083                            return true;
084                    }
085                    else {
086                            return false;
087                    }
088            }
089    
090    }