1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
20  import com.liferay.portal.model.Ticket;
21  import com.liferay.portal.service.ServiceContext;
22  import com.liferay.portal.service.base.TicketLocalServiceBaseImpl;
23  import com.liferay.portal.util.PortalUtil;
24  
25  import java.util.Date;
26  
27  /**
28   * <a href="TicketLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Mika Koivisto
31   */
32  public class TicketLocalServiceImpl extends TicketLocalServiceBaseImpl {
33  
34      public Ticket addTicket(
35              long companyId, String className, long classPK, Date expirationDate,
36              ServiceContext serviceContext)
37          throws SystemException {
38  
39          long classNameId = PortalUtil.getClassNameId(className);
40          Date now = new Date();
41  
42          long ticketId = counterLocalService.increment();
43  
44          Ticket ticket = ticketPersistence.create(ticketId);
45  
46          ticket.setCompanyId(companyId);
47          ticket.setCreateDate(now);
48          ticket.setClassNameId(classNameId);
49          ticket.setClassPK(classPK);
50          ticket.setKey(PortalUUIDUtil.generate());
51          ticket.setExpirationDate(expirationDate);
52  
53          ticketPersistence.update(ticket, false);
54  
55          return ticket;
56      }
57  
58      public Ticket getTicket(String key)
59          throws PortalException, SystemException {
60  
61          return ticketPersistence.findByKey(key);
62      }
63  
64  }