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.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, int type,
034                            String extraInfo, Date expirationDate,
035                            ServiceContext serviceContext)
036                    throws SystemException {
037    
038                    long classNameId = PortalUtil.getClassNameId(className);
039                    Date now = new Date();
040    
041                    long ticketId = counterLocalService.increment();
042    
043                    Ticket ticket = ticketPersistence.create(ticketId);
044    
045                    ticket.setCompanyId(companyId);
046                    ticket.setCreateDate(now);
047                    ticket.setClassNameId(classNameId);
048                    ticket.setClassPK(classPK);
049                    ticket.setKey(PortalUUIDUtil.generate());
050                    ticket.setType(type);
051                    ticket.setExtraInfo(extraInfo);
052                    ticket.setExpirationDate(expirationDate);
053    
054                    ticketPersistence.update(ticket, false);
055    
056                    return ticket;
057            }
058    
059            public Ticket fetchTicket(String key) throws SystemException {
060                    return ticketPersistence.fetchByKey(key);
061            }
062    
063            public Ticket getTicket(String key)
064                    throws PortalException, SystemException {
065    
066                    return ticketPersistence.findByKey(key);
067            }
068    
069    }