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.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
020    import com.liferay.portal.model.Ticket;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.service.base.TicketLocalServiceBaseImpl;
023    import com.liferay.portal.util.PortalUtil;
024    
025    import java.util.Date;
026    
027    /**
028     * @author Mika Koivisto
029     */
030    public class TicketLocalServiceImpl extends TicketLocalServiceBaseImpl {
031    
032            public Ticket addTicket(
033                            long companyId, String className, long classPK, Date expirationDate,
034                            ServiceContext serviceContext)
035                    throws SystemException {
036    
037                    long classNameId = PortalUtil.getClassNameId(className);
038                    Date now = new Date();
039    
040                    long ticketId = counterLocalService.increment();
041    
042                    Ticket ticket = ticketPersistence.create(ticketId);
043    
044                    ticket.setCompanyId(companyId);
045                    ticket.setCreateDate(now);
046                    ticket.setClassNameId(classNameId);
047                    ticket.setClassPK(classPK);
048                    ticket.setKey(PortalUUIDUtil.generate());
049                    ticket.setExpirationDate(expirationDate);
050    
051                    ticketPersistence.update(ticket, false);
052    
053                    return ticket;
054            }
055    
056            public Ticket getTicket(String key)
057                    throws PortalException, SystemException {
058    
059                    return ticketPersistence.findByKey(key);
060            }
061    
062    }