001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.tags.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.model.User;
026: import com.liferay.portlet.tags.PropertyKeyException;
027: import com.liferay.portlet.tags.PropertyValueException;
028: import com.liferay.portlet.tags.model.TagsEntry;
029: import com.liferay.portlet.tags.model.TagsProperty;
030: import com.liferay.portlet.tags.service.base.TagsPropertyLocalServiceBaseImpl;
031: import com.liferay.portlet.tags.util.TagsUtil;
032:
033: import java.util.Date;
034: import java.util.Iterator;
035: import java.util.List;
036:
037: /**
038: * <a href="TagsPropertyLocalServiceImpl.java.html"><b><i>View Source</i></b>
039: * </a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class TagsPropertyLocalServiceImpl extends
045: TagsPropertyLocalServiceBaseImpl {
046:
047: public TagsProperty addProperty(long userId, long entryId,
048: String key, String value) throws PortalException,
049: SystemException {
050:
051: User user = userPersistence.findByPrimaryKey(userId);
052: Date now = new Date();
053:
054: validate(key, value);
055:
056: long propertyId = counterLocalService.increment();
057:
058: TagsProperty property = tagsPropertyPersistence
059: .create(propertyId);
060:
061: property.setCompanyId(user.getCompanyId());
062: property.setUserId(user.getUserId());
063: property.setUserName(user.getFullName());
064: property.setCreateDate(now);
065: property.setModifiedDate(now);
066: property.setEntryId(entryId);
067: property.setKey(key);
068: property.setValue(value);
069:
070: tagsPropertyPersistence.update(property);
071:
072: return property;
073: }
074:
075: public TagsProperty addProperty(long userId, String entryName,
076: String key, String value) throws PortalException,
077: SystemException {
078:
079: User user = userPersistence.findByPrimaryKey(userId);
080:
081: TagsEntry entry = tagsEntryLocalService.getEntry(user
082: .getCompanyId(), entryName);
083:
084: return addProperty(userId, entry.getEntryId(), key, value);
085: }
086:
087: public void deleteProperties(long entryId) throws PortalException,
088: SystemException {
089:
090: Iterator itr = tagsPropertyPersistence.findByEntryId(entryId)
091: .iterator();
092:
093: while (itr.hasNext()) {
094: TagsProperty property = (TagsProperty) itr.next();
095:
096: deleteProperty(property);
097: }
098: }
099:
100: public void deleteProperty(long propertyId) throws PortalException,
101: SystemException {
102:
103: TagsProperty property = tagsPropertyPersistence
104: .findByPrimaryKey(propertyId);
105:
106: deleteProperty(property);
107: }
108:
109: public void deleteProperty(TagsProperty property)
110: throws PortalException, SystemException {
111:
112: tagsPropertyPersistence.remove(property.getPropertyId());
113: }
114:
115: public List getProperties() throws SystemException {
116: return tagsPropertyPersistence.findAll();
117: }
118:
119: public List getProperties(long entryId) throws SystemException {
120: return tagsPropertyPersistence.findByEntryId(entryId);
121: }
122:
123: public TagsProperty getProperty(long propertyId)
124: throws PortalException, SystemException {
125:
126: return tagsPropertyPersistence.findByPrimaryKey(propertyId);
127: }
128:
129: public TagsProperty getProperty(long entryId, String key)
130: throws PortalException, SystemException {
131:
132: return tagsPropertyPersistence.findByE_K(entryId, key);
133: }
134:
135: public String[] getPropertyKeys(long companyId)
136: throws SystemException {
137: return tagsPropertyKeyFinder.findByCompanyId(companyId);
138: }
139:
140: public List getPropertyValues(long companyId, String key)
141: throws SystemException {
142:
143: return tagsPropertyFinder.findByC_K(companyId, key);
144: }
145:
146: public TagsProperty updateProperty(long propertyId, String key,
147: String value) throws PortalException, SystemException {
148:
149: validate(key, value);
150:
151: TagsProperty property = tagsPropertyPersistence
152: .findByPrimaryKey(propertyId);
153:
154: property.setModifiedDate(new Date());
155: property.setKey(key);
156: property.setValue(value);
157:
158: tagsPropertyPersistence.update(property);
159:
160: return property;
161: }
162:
163: protected void validate(String key, String value)
164: throws PortalException, SystemException {
165:
166: if (!TagsUtil.isValidWord(key)) {
167: throw new PropertyKeyException();
168: }
169:
170: if (!TagsUtil.isValidWord(value)) {
171: throw new PropertyValueException();
172: }
173: }
174:
175: }
|