1
22
23 package com.liferay.portal.service.impl;
24
25 import com.liferay.portal.NoSuchPortletItemException;
26 import com.liferay.portal.PortalException;
27 import com.liferay.portal.PortletItemNameException;
28 import com.liferay.portal.SystemException;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portal.model.PortletItem;
31 import com.liferay.portal.model.PortletPreferences;
32 import com.liferay.portal.model.User;
33 import com.liferay.portal.service.base.PortletItemLocalServiceBaseImpl;
34 import com.liferay.portal.util.PortalUtil;
35
36 import java.util.Date;
37 import java.util.List;
38
39
44 public class PortletItemLocalServiceImpl
45 extends PortletItemLocalServiceBaseImpl {
46
47 public PortletItem addPortletItem(
48 long userId, long groupId, String name, String portletId,
49 String className)
50 throws PortalException, SystemException {
51
52 User user = userPersistence.findByPrimaryKey(userId);
53 long classNameId = PortalUtil.getClassNameId(className);
54 Date now = new Date();
55
56 validate(name);
57
58 long portletItemId = counterLocalService.increment();
59
60 PortletItem portletItem = portletItemPersistence.create(
61 portletItemId);
62
63 portletItem.setGroupId(groupId);
64 portletItem.setCompanyId(user.getCompanyId());
65 portletItem.setUserId(user.getUserId());
66 portletItem.setUserName(user.getFullName());
67 portletItem.setCreateDate(now);
68 portletItem.setModifiedDate(now);
69 portletItem.setName(name);
70 portletItem.setPortletId(portletId);
71 portletItem.setClassNameId(classNameId);
72
73 portletItemPersistence.update(portletItem, false);
74
75 return portletItem;
76 }
77
78 public PortletItem getPortletItem(long portletItemId)
79 throws PortalException, SystemException {
80
81 return portletItemPersistence.findByPrimaryKey(portletItemId);
82 }
83
84 public PortletItem getPortletItem(
85 long groupId, String name, String portletId, String className)
86 throws PortalException, SystemException {
87
88 long classNameId = PortalUtil.getClassNameId(className);
89
90 return portletItemPersistence.findByG_N_P_C(
91 groupId, name, portletId, classNameId);
92 }
93
94 public List<PortletItem> getPortletItems(long groupId, String className)
95 throws SystemException {
96
97 long classNameId = PortalUtil.getClassNameId(className);
98
99 return portletItemPersistence.findByG_C(groupId, classNameId);
100 }
101
102 public List<PortletItem> getPortletItems(
103 long groupId, String portletId, String className)
104 throws SystemException {
105
106 long classNameId = PortalUtil.getClassNameId(className);
107
108 return portletItemPersistence.findByG_P_C(
109 groupId, portletId, classNameId);
110 }
111
112 public PortletItem updatePortletItem(
113 long userId, long groupId, String name, String portletId,
114 String className)
115 throws PortalException, SystemException {
116
117 PortletItem portletItem = null;
118
119 try {
120 User user = userPersistence.findByPrimaryKey(userId);
121
122 portletItem = getPortletItem(
123 groupId, name, portletId, PortletPreferences.class.getName());
124
125 portletItem.setUserId(userId);
126 portletItem.setUserName(user.getFullName());
127 portletItem.setModifiedDate(new Date());
128
129 portletItemPersistence.update(portletItem, false);
130 }
131 catch (NoSuchPortletItemException nsste) {
132 portletItem = addPortletItem(
133 userId, groupId, name, portletId,
134 PortletPreferences.class.getName());
135 }
136
137 return portletItem;
138 }
139
140 protected void validate(String name) throws PortalException {
141 if (Validator.isNull(name)) {
142 throw new PortletItemNameException();
143 }
144 }
145
146 }