001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.NoSuchPortletItemException;
018 import com.liferay.portal.PortletItemNameException;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.util.Validator;
021 import com.liferay.portal.model.PortletItem;
022 import com.liferay.portal.model.PortletPreferences;
023 import com.liferay.portal.model.User;
024 import com.liferay.portal.service.base.PortletItemLocalServiceBaseImpl;
025
026 import java.util.Date;
027 import java.util.List;
028
029
032 public class PortletItemLocalServiceImpl
033 extends PortletItemLocalServiceBaseImpl {
034
035 @Override
036 public PortletItem addPortletItem(
037 long userId, long groupId, String name, String portletId,
038 String className)
039 throws PortalException {
040
041 User user = userPersistence.findByPrimaryKey(userId);
042 long classNameId = classNameLocalService.getClassNameId(className);
043 Date now = new Date();
044
045 validate(name);
046
047 long portletItemId = counterLocalService.increment();
048
049 PortletItem portletItem = portletItemPersistence.create(portletItemId);
050
051 portletItem.setGroupId(groupId);
052 portletItem.setCompanyId(user.getCompanyId());
053 portletItem.setUserId(user.getUserId());
054 portletItem.setUserName(user.getFullName());
055 portletItem.setCreateDate(now);
056 portletItem.setModifiedDate(now);
057 portletItem.setName(name);
058 portletItem.setPortletId(portletId);
059 portletItem.setClassNameId(classNameId);
060
061 portletItemPersistence.update(portletItem);
062
063 return portletItem;
064 }
065
066 @Override
067 public PortletItem getPortletItem(
068 long groupId, String name, String portletId, String className)
069 throws PortalException {
070
071 long classNameId = classNameLocalService.getClassNameId(className);
072
073 return portletItemPersistence.findByG_N_P_C(
074 groupId, name, portletId, classNameId);
075 }
076
077 @Override
078 public List<PortletItem> getPortletItems(long groupId, String className) {
079 long classNameId = classNameLocalService.getClassNameId(className);
080
081 return portletItemPersistence.findByG_C(groupId, classNameId);
082 }
083
084 @Override
085 public List<PortletItem> getPortletItems(
086 long groupId, String portletId, String className) {
087
088 long classNameId = classNameLocalService.getClassNameId(className);
089
090 return portletItemPersistence.findByG_P_C(
091 groupId, portletId, classNameId);
092 }
093
094 @Override
095 public PortletItem updatePortletItem(
096 long userId, long groupId, String name, String portletId,
097 String className)
098 throws PortalException {
099
100 PortletItem portletItem = null;
101
102 try {
103 User user = userPersistence.findByPrimaryKey(userId);
104
105 portletItem = getPortletItem(
106 groupId, name, portletId, PortletPreferences.class.getName());
107
108 portletItem.setUserId(userId);
109 portletItem.setUserName(user.getFullName());
110 portletItem.setModifiedDate(new Date());
111
112 portletItemPersistence.update(portletItem);
113 }
114 catch (NoSuchPortletItemException nspie) {
115 portletItem = addPortletItem(
116 userId, groupId, name, portletId,
117 PortletPreferences.class.getName());
118 }
119
120 return portletItem;
121 }
122
123 protected void validate(String name) throws PortalException {
124 if (Validator.isNull(name)) {
125 throw new PortletItemNameException();
126 }
127 }
128
129 }