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