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.portlet.announcements.model.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.model.Group;
20  import com.liferay.portal.model.Organization;
21  import com.liferay.portal.service.GroupLocalServiceUtil;
22  import com.liferay.portal.service.OrganizationLocalServiceUtil;
23  import com.liferay.portlet.announcements.model.AnnouncementsEntry;
24  
25  /**
26   * <a href="AnnouncementsEntryImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   * @author Wesley Gong
30   */
31  public class AnnouncementsEntryImpl
32      extends AnnouncementsEntryModelImpl implements AnnouncementsEntry {
33  
34      public AnnouncementsEntryImpl() {
35      }
36  
37      public long getGroupId() throws PortalException, SystemException {
38          long groupId = 0;
39  
40          long classPK = getClassPK();
41  
42          if (classPK > 0) {
43              String className = getClassName();
44  
45              if (className.equals(Group.class.getName())) {
46                  Group group = GroupLocalServiceUtil.getGroup(classPK);
47  
48                  groupId = group.getGroupId();
49              }
50              else if (className.equals(Organization.class.getName())) {
51                  Organization organization =
52                      OrganizationLocalServiceUtil.getOrganization(classPK);
53  
54                  Group group = organization.getGroup();
55  
56                  groupId = group.getGroupId();
57              }
58          }
59  
60          return groupId;
61      }
62  
63  }