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.portlet.polls.model.impl;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.service.ServiceContext;
019    import com.liferay.portlet.polls.model.PollsChoice;
020    import com.liferay.portlet.polls.service.PollsChoiceLocalServiceUtil;
021    import com.liferay.portlet.polls.service.PollsVoteLocalServiceUtil;
022    
023    import java.util.Date;
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class PollsQuestionImpl extends PollsQuestionBaseImpl {
030    
031            public PollsQuestionImpl() {
032            }
033    
034            public List<PollsChoice> getChoices() throws SystemException {
035                    return PollsChoiceLocalServiceUtil.getChoices(getQuestionId());
036            }
037    
038            public int getVotesCount() throws SystemException {
039                    return PollsVoteLocalServiceUtil.getQuestionVotesCount(getQuestionId());
040            }
041    
042            public boolean isExpired() {
043                    Date expirationDate = getExpirationDate();
044    
045                    if ((expirationDate != null) && (expirationDate.before(new Date()))) {
046                            return true;
047                    }
048                    else {
049                            return false;
050                    }
051            }
052    
053            public boolean isExpired(
054                    ServiceContext serviceContext, Date defaultCreateDate) {
055    
056                    Date expirationDate = getExpirationDate();
057    
058                    if (expirationDate == null) {
059                            return false;
060                    }
061    
062                    Date createDate = serviceContext.getCreateDate(defaultCreateDate);
063    
064                    if (createDate.after(expirationDate)) {
065                            return true;
066                    }
067                    else {
068                            return false;
069                    }
070            }
071    
072    }