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