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