001    /**
002     * Copyright (c) 2000-2010 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.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    }