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