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.documentlibrary.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.security.permission.ActionKeys;
026: import com.liferay.portal.model.User;
027: import com.liferay.portlet.documentlibrary.model.DLFileEntry;
028: import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
029: import com.liferay.portlet.documentlibrary.service.base.DLFileEntryServiceBaseImpl;
030: import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
031: import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
032: import com.liferay.portlet.documentlibrary.util.DLUtil;
033:
034: import java.rmi.RemoteException;
035:
036: /**
037: * <a href="DLFileEntryServiceImpl.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class DLFileEntryServiceImpl extends DLFileEntryServiceBaseImpl {
043:
044: public DLFileEntry addFileEntry(long folderId, String name,
045: String title, String description, String[] tagsEntries,
046: String extraSettings, byte[] byteArray,
047: boolean addCommunityPermissions, boolean addGuestPermissions)
048: throws PortalException, SystemException {
049:
050: DLFolderPermission.check(getPermissionChecker(), folderId,
051: ActionKeys.ADD_DOCUMENT);
052:
053: return dlFileEntryLocalService.addFileEntry(getUserId(),
054: folderId, name, title, description, tagsEntries,
055: extraSettings, byteArray, addCommunityPermissions,
056: addGuestPermissions);
057: }
058:
059: public DLFileEntry addFileEntry(long folderId, String name,
060: String title, String description, String[] tagsEntries,
061: String extraSettings, byte[] byteArray,
062: String[] communityPermissions, String[] guestPermissions)
063: throws PortalException, SystemException {
064:
065: DLFolderPermission.check(getPermissionChecker(), folderId,
066: ActionKeys.ADD_DOCUMENT);
067:
068: return dlFileEntryLocalService.addFileEntry(getUserId(),
069: folderId, name, title, description, tagsEntries,
070: extraSettings, byteArray, communityPermissions,
071: guestPermissions);
072: }
073:
074: public void deleteFileEntry(long folderId, String name)
075: throws PortalException, RemoteException, SystemException {
076:
077: User user = getUser();
078:
079: DLFileEntryPermission.check(getPermissionChecker(), folderId,
080: name, ActionKeys.DELETE);
081:
082: String lockId = DLUtil.getLockId(folderId, name);
083:
084: boolean alreadyHasLock = lockService.hasLock(DLFileEntry.class
085: .getName(), lockId, user.getUserId());
086:
087: if (!alreadyHasLock) {
088:
089: // Lock
090:
091: lockService.lock(DLFileEntry.class.getName(), lockId, user
092: .getCompanyId(), user.getUserId(),
093: DLFileEntryImpl.LOCK_EXPIRATION_TIME);
094: }
095:
096: dlFileEntryLocalService.deleteFileEntry(folderId, name);
097:
098: if (!alreadyHasLock) {
099:
100: // Unlock
101:
102: lockService.unlock(DLFileEntry.class.getName(), lockId);
103: }
104: }
105:
106: public void deleteFileEntry(long folderId, String name,
107: double version) throws PortalException, RemoteException,
108: SystemException {
109:
110: User user = getUser();
111:
112: DLFileEntryPermission.check(getPermissionChecker(), folderId,
113: name, ActionKeys.DELETE);
114:
115: String lockId = DLUtil.getLockId(folderId, name);
116:
117: boolean alreadyHasLock = lockService.hasLock(DLFileEntry.class
118: .getName(), lockId, user.getUserId());
119:
120: if (!alreadyHasLock) {
121:
122: // Lock
123:
124: lockService.lock(DLFileEntry.class.getName(), lockId, user
125: .getCompanyId(), user.getUserId(),
126: DLFileEntryImpl.LOCK_EXPIRATION_TIME);
127: }
128:
129: dlFileEntryLocalService
130: .deleteFileEntry(folderId, name, version);
131:
132: if (!alreadyHasLock) {
133:
134: // Unlock
135:
136: lockService.unlock(DLFileEntry.class.getName(), lockId);
137: }
138: }
139:
140: public void deleteFileEntryByTitle(long folderId,
141: String titleWithExtension) throws PortalException,
142: RemoteException, SystemException {
143:
144: DLFileEntry fileEntry = getFileEntryByTitle(folderId,
145: titleWithExtension);
146:
147: deleteFileEntry(folderId, fileEntry.getName());
148: }
149:
150: public DLFileEntry getFileEntry(long folderId, String name)
151: throws PortalException, SystemException {
152:
153: DLFileEntryPermission.check(getPermissionChecker(), folderId,
154: name, ActionKeys.VIEW);
155:
156: return dlFileEntryLocalService.getFileEntry(folderId, name);
157: }
158:
159: public DLFileEntry getFileEntryByTitle(long folderId,
160: String titleWithExtension) throws PortalException,
161: SystemException {
162:
163: DLFileEntry fileEntry = dlFileEntryLocalService
164: .getFileEntryByTitle(folderId, titleWithExtension);
165:
166: DLFileEntryPermission.check(getPermissionChecker(), fileEntry,
167: ActionKeys.VIEW);
168:
169: return fileEntry;
170: }
171:
172: public void lockFileEntry(long folderId, String name)
173: throws PortalException, RemoteException, SystemException {
174:
175: User user = getUser();
176:
177: String lockId = DLUtil.getLockId(folderId, name);
178:
179: lockService.lock(DLFileEntry.class.getName(), lockId, user
180: .getCompanyId(), user.getUserId(),
181: DLFileEntryImpl.LOCK_EXPIRATION_TIME);
182: }
183:
184: public void unlockFileEntry(long folderId, String name)
185: throws PortalException, RemoteException, SystemException {
186:
187: String lockId = DLUtil.getLockId(folderId, name);
188:
189: lockService.unlock(DLFileEntry.class.getName(), lockId);
190: }
191:
192: public DLFileEntry updateFileEntry(long folderId, long newFolderId,
193: String name, String sourceFileName, String title,
194: String description, String[] tagsEntries,
195: String extraSettings, byte[] byteArray)
196: throws PortalException, RemoteException, SystemException {
197:
198: User user = getUser();
199:
200: DLFileEntryPermission.check(getPermissionChecker(), folderId,
201: name, ActionKeys.UPDATE);
202:
203: String lockId = DLUtil.getLockId(folderId, name);
204:
205: boolean alreadyHasLock = lockService.hasLock(DLFileEntry.class
206: .getName(), lockId, user.getUserId());
207:
208: if (!alreadyHasLock) {
209:
210: // Lock
211:
212: lockService.lock(DLFileEntry.class.getName(), lockId, user
213: .getCompanyId(), user.getUserId(),
214: DLFileEntryImpl.LOCK_EXPIRATION_TIME);
215: }
216:
217: DLFileEntry fileEntry = dlFileEntryLocalService
218: .updateFileEntry(getUserId(), folderId, newFolderId,
219: name, sourceFileName, title, description,
220: tagsEntries, extraSettings, byteArray);
221:
222: if (!alreadyHasLock) {
223:
224: // Unlock
225:
226: lockService.unlock(DLFileEntry.class.getName(), lockId);
227: }
228:
229: return fileEntry;
230: }
231:
232: }
|