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