1
22
23 package com.liferay.portlet.documentlibrary.service.impl;
24
25 import com.liferay.lock.service.LockServiceUtil;
26 import com.liferay.portal.PortalException;
27 import com.liferay.portal.SystemException;
28 import com.liferay.portal.kernel.security.permission.ActionKeys;
29 import com.liferay.portal.model.User;
30 import com.liferay.portal.service.impl.PrincipalBean;
31 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
32 import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
33 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
34 import com.liferay.portlet.documentlibrary.service.DLFileEntryService;
35 import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
36 import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
37 import com.liferay.portlet.documentlibrary.util.DLUtil;
38
39 import java.rmi.RemoteException;
40
41
47 public class DLFileEntryServiceImpl
48 extends PrincipalBean implements DLFileEntryService {
49
50 public DLFileEntry addFileEntry(
51 long folderId, String name, String title, String description,
52 String[] tagsEntries, String extraSettings, byte[] byteArray,
53 boolean addCommunityPermissions, boolean addGuestPermissions)
54 throws PortalException, SystemException {
55
56 DLFolderPermission.check(
57 getPermissionChecker(), folderId, ActionKeys.ADD_DOCUMENT);
58
59 return DLFileEntryLocalServiceUtil.addFileEntry(
60 getUserId(), folderId, name, title, description, tagsEntries,
61 extraSettings, byteArray, addCommunityPermissions,
62 addGuestPermissions);
63 }
64
65 public DLFileEntry addFileEntry(
66 long folderId, String name, String title, String description,
67 String[] tagsEntries, String extraSettings, byte[] byteArray,
68 String[] communityPermissions, String[] guestPermissions)
69 throws PortalException, SystemException {
70
71 DLFolderPermission.check(
72 getPermissionChecker(), folderId, ActionKeys.ADD_DOCUMENT);
73
74 return DLFileEntryLocalServiceUtil.addFileEntry(
75 getUserId(), folderId, name, title, description, tagsEntries,
76 extraSettings, byteArray, communityPermissions, guestPermissions);
77 }
78
79 public void deleteFileEntry(long folderId, String name)
80 throws PortalException, RemoteException, SystemException {
81
82 User user = getUser();
83
84 DLFileEntryPermission.check(
85 getPermissionChecker(), folderId, name, ActionKeys.DELETE);
86
87 String lockId = DLUtil.getLockId(folderId, name);
88
89 boolean alreadyHasLock = LockServiceUtil.hasLock(
90 DLFileEntry.class.getName(), lockId, user.getUserId());
91
92 if (!alreadyHasLock) {
93
94
96 LockServiceUtil.lock(
97 DLFileEntry.class.getName(), lockId, user.getCompanyId(),
98 user.getUserId(), DLFileEntryImpl.LOCK_EXPIRATION_TIME);
99 }
100
101 DLFileEntryLocalServiceUtil.deleteFileEntry(folderId, name);
102
103 if (!alreadyHasLock) {
104
105
107 LockServiceUtil.unlock(DLFileEntry.class.getName(), lockId);
108 }
109 }
110
111 public void deleteFileEntry(long folderId, String name, double version)
112 throws PortalException, RemoteException, SystemException {
113
114 User user = getUser();
115
116 DLFileEntryPermission.check(
117 getPermissionChecker(), folderId, name, ActionKeys.DELETE);
118
119 String lockId = DLUtil.getLockId(folderId, name);
120
121 boolean alreadyHasLock = LockServiceUtil.hasLock(
122 DLFileEntry.class.getName(), lockId, user.getUserId());
123
124 if (!alreadyHasLock) {
125
126
128 LockServiceUtil.lock(
129 DLFileEntry.class.getName(), lockId, user.getCompanyId(),
130 user.getUserId(), DLFileEntryImpl.LOCK_EXPIRATION_TIME);
131 }
132
133 DLFileEntryLocalServiceUtil.deleteFileEntry(folderId, name, version);
134
135 if (!alreadyHasLock) {
136
137
139 LockServiceUtil.unlock(DLFileEntry.class.getName(), lockId);
140 }
141 }
142
143 public DLFileEntry getFileEntry(long folderId, String name)
144 throws PortalException, SystemException {
145
146 DLFileEntryPermission.check(
147 getPermissionChecker(), folderId, name, ActionKeys.VIEW);
148
149 return DLFileEntryLocalServiceUtil.getFileEntry(folderId, name);
150 }
151
152 public void lockFileEntry(long folderId, String name)
153 throws PortalException, RemoteException, SystemException {
154
155 User user = getUser();
156
157 String lockId = DLUtil.getLockId(folderId, name);
158
159 LockServiceUtil.lock(
160 DLFileEntry.class.getName(), lockId, user.getCompanyId(),
161 user.getUserId(), DLFileEntryImpl.LOCK_EXPIRATION_TIME);
162 }
163
164 public void unlockFileEntry(long folderId, String name)
165 throws PortalException, RemoteException, SystemException {
166
167 String lockId = DLUtil.getLockId(folderId, name);
168
169 LockServiceUtil.unlock(DLFileEntry.class.getName(), lockId);
170 }
171
172 public DLFileEntry updateFileEntry(
173 long folderId, long newFolderId, String name, String sourceFileName,
174 String title, String description, String[] tagsEntries,
175 String extraSettings, byte[] byteArray)
176 throws PortalException, RemoteException, SystemException {
177
178 User user = getUser();
179
180 DLFileEntryPermission.check(
181 getPermissionChecker(), folderId, name, ActionKeys.UPDATE);
182
183 String lockId = DLUtil.getLockId(folderId, name);
184
185 boolean alreadyHasLock = LockServiceUtil.hasLock(
186 DLFileEntry.class.getName(), lockId, user.getUserId());
187
188 if (!alreadyHasLock) {
189
190
192 LockServiceUtil.lock(
193 DLFileEntry.class.getName(), lockId, user.getCompanyId(),
194 user.getUserId(), DLFileEntryImpl.LOCK_EXPIRATION_TIME);
195 }
196
197 DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.updateFileEntry(
198 getUserId(), folderId, newFolderId, name, sourceFileName, title,
199 description, tagsEntries, extraSettings, byteArray);
200
201 if (!alreadyHasLock) {
202
203
205 LockServiceUtil.unlock(DLFileEntry.class.getName(), lockId);
206 }
207
208 return fileEntry;
209 }
210
211 }