Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / server / ejb / GSSDAOBean.java @ 376d0ebf

History | View | Annotate | Download (25.2 kB)

1 14ad7326 pastith
/*
2 82248972 Panagiotis Astithas
 * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
3 14ad7326 pastith
 *
4 14ad7326 pastith
 * This file is part of GSS.
5 14ad7326 pastith
 *
6 14ad7326 pastith
 * GSS is free software: you can redistribute it and/or modify
7 14ad7326 pastith
 * it under the terms of the GNU General Public License as published by
8 14ad7326 pastith
 * the Free Software Foundation, either version 3 of the License, or
9 14ad7326 pastith
 * (at your option) any later version.
10 14ad7326 pastith
 *
11 14ad7326 pastith
 * GSS is distributed in the hope that it will be useful,
12 14ad7326 pastith
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14ad7326 pastith
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14ad7326 pastith
 * GNU General Public License for more details.
15 14ad7326 pastith
 *
16 14ad7326 pastith
 * You should have received a copy of the GNU General Public License
17 14ad7326 pastith
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 14ad7326 pastith
 */
19 14ad7326 pastith
package gr.ebs.gss.server.ejb;
20 14ad7326 pastith
21 01a30cd0 Panagiotis Astithas
import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
22 14ad7326 pastith
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
23 8f128261 droutsis
import gr.ebs.gss.server.domain.AccountingInfo;
24 14ad7326 pastith
import gr.ebs.gss.server.domain.FileBody;
25 14ad7326 pastith
import gr.ebs.gss.server.domain.FileHeader;
26 14ad7326 pastith
import gr.ebs.gss.server.domain.FileUploadStatus;
27 14ad7326 pastith
import gr.ebs.gss.server.domain.Folder;
28 14ad7326 pastith
import gr.ebs.gss.server.domain.Group;
29 82248972 Panagiotis Astithas
import gr.ebs.gss.server.domain.Invitation;
30 14ad7326 pastith
import gr.ebs.gss.server.domain.Nonce;
31 14ad7326 pastith
import gr.ebs.gss.server.domain.User;
32 01a30cd0 Panagiotis Astithas
import gr.ebs.gss.server.domain.UserClass;
33 14ad7326 pastith
34 14ad7326 pastith
import java.util.ArrayList;
35 8f128261 droutsis
import java.util.Calendar;
36 8f128261 droutsis
import java.util.Date;
37 8f128261 droutsis
import java.util.GregorianCalendar;
38 14ad7326 pastith
import java.util.HashSet;
39 14ad7326 pastith
import java.util.List;
40 14ad7326 pastith
import java.util.Set;
41 14ad7326 pastith
42 14ad7326 pastith
import javax.ejb.Stateless;
43 14ad7326 pastith
import javax.persistence.EntityManager;
44 14ad7326 pastith
import javax.persistence.NoResultException;
45 14ad7326 pastith
import javax.persistence.PersistenceContext;
46 14ad7326 pastith
47 14ad7326 pastith
import org.apache.commons.lang.StringUtils;
48 14ad7326 pastith
49 14ad7326 pastith
/**
50 14ad7326 pastith
 * The implementation of the GSSDAO interface.
51 14ad7326 pastith
 */
52 14ad7326 pastith
@Stateless
53 14ad7326 pastith
public class GSSDAOBean implements GSSDAO {
54 14ad7326 pastith
55 8f128261 droutsis
        private static final int BANDWIDTH_TIME_PERIOD_FIELD = Calendar.MONTH;
56 8f128261 droutsis
        private static final int BANDWIDTH_TIME_PERIOD_AMOUNT = 1;
57 8f128261 droutsis
58 14ad7326 pastith
        /**
59 14ad7326 pastith
         * The entity manager for the persistence unit
60 14ad7326 pastith
         */
61 14ad7326 pastith
        @PersistenceContext(unitName = "gss")
62 14ad7326 pastith
        private EntityManager manager;
63 14ad7326 pastith
64 023f6f1e Panagiotis Astithas
        @Override
65 14ad7326 pastith
        public Folder getRootFolder(final Long userId) throws ObjectNotFoundException {
66 14ad7326 pastith
                try {
67 14ad7326 pastith
                        if (userId == null)
68 14ad7326 pastith
                                throw new ObjectNotFoundException("No user specified");
69 14ad7326 pastith
                        return (Folder) manager        .createQuery("select f from Folder f where f.owner.id=:ownerId and f.parent is null")
70 14ad7326 pastith
                                                                        .setParameter("ownerId", userId)
71 14ad7326 pastith
                                                                        .getSingleResult();
72 14ad7326 pastith
                } catch (final NoResultException e) {
73 14ad7326 pastith
                        throw new ObjectNotFoundException("Root folder not found for user with id=" + userId);
74 14ad7326 pastith
                }
75 14ad7326 pastith
        }
76 14ad7326 pastith
77 023f6f1e Panagiotis Astithas
        @Override
78 14ad7326 pastith
        public User getUser(final String username) throws ObjectNotFoundException {
79 14ad7326 pastith
                try {
80 14ad7326 pastith
                        if (username == null)
81 14ad7326 pastith
                                throw new ObjectNotFoundException("No user specified");
82 14ad7326 pastith
                        return (User) manager        .createQuery("select f from User f where f.username=:username")
83 14ad7326 pastith
                                                                        .setParameter("username", username)
84 14ad7326 pastith
                                                                        .getSingleResult();
85 14ad7326 pastith
                } catch (final NoResultException e) {
86 14ad7326 pastith
                        throw new ObjectNotFoundException("No User found for username=" + username);
87 14ad7326 pastith
                }
88 14ad7326 pastith
        }
89 14ad7326 pastith
90 023f6f1e Panagiotis Astithas
        @Override
91 14ad7326 pastith
        public void create(final Object obj) {
92 14ad7326 pastith
                if (obj == null)
93 14ad7326 pastith
                        throw new IllegalArgumentException("No object speficied");
94 14ad7326 pastith
                manager.persist(obj);
95 14ad7326 pastith
        }
96 14ad7326 pastith
97 023f6f1e Panagiotis Astithas
        @Override
98 14ad7326 pastith
        public void refresh(final Object obj) {
99 14ad7326 pastith
                if (obj == null)
100 14ad7326 pastith
                        throw new IllegalArgumentException("No object speficied");
101 14ad7326 pastith
                manager.refresh(obj);
102 14ad7326 pastith
        }
103 14ad7326 pastith
104 023f6f1e Panagiotis Astithas
        @Override
105 14ad7326 pastith
        public void update(final Object obj) {
106 14ad7326 pastith
                if (obj == null)
107 14ad7326 pastith
                        throw new IllegalArgumentException("No object speficied");
108 14ad7326 pastith
                manager.merge(obj);
109 14ad7326 pastith
        }
110 14ad7326 pastith
111 023f6f1e Panagiotis Astithas
        @Override
112 14ad7326 pastith
        public void delete(final Object entity) {
113 14ad7326 pastith
                if (entity == null)
114 14ad7326 pastith
                        throw new IllegalArgumentException("No object speficied");
115 14ad7326 pastith
                manager.remove(entity);
116 14ad7326 pastith
        }
117 14ad7326 pastith
118 023f6f1e Panagiotis Astithas
        @Override
119 14ad7326 pastith
        public <T> T getEntityById(final Class<T> _class, final Object _id) throws ObjectNotFoundException {
120 14ad7326 pastith
                if (_id == null)
121 14ad7326 pastith
                        throw new ObjectNotFoundException("No " + _class.getSimpleName() + " specified");
122 14ad7326 pastith
123 14ad7326 pastith
                final T entity = manager.find(_class, _id);
124 14ad7326 pastith
                if (entity == null)
125 14ad7326 pastith
                        throw new ObjectNotFoundException(_class.getSimpleName() + " with id=" + _id + " was not found");
126 14ad7326 pastith
127 14ad7326 pastith
                return entity;
128 14ad7326 pastith
        }
129 14ad7326 pastith
130 023f6f1e Panagiotis Astithas
        @Override
131 14ad7326 pastith
        @SuppressWarnings("unchecked")
132 14ad7326 pastith
        public List<Group> getGroups(final Long userId) throws ObjectNotFoundException {
133 14ad7326 pastith
                if (userId == null)
134 14ad7326 pastith
                        throw new ObjectNotFoundException("No user specified");
135 14ad7326 pastith
136 14ad7326 pastith
                return manager.createQuery("select g from Group g where g.owner.id=:userId").setParameter("userId", userId).getResultList();
137 14ad7326 pastith
        }
138 14ad7326 pastith
139 023f6f1e Panagiotis Astithas
        @Override
140 14ad7326 pastith
        @SuppressWarnings("unchecked")
141 cc154eca droutsis
        public List<FileHeader> getFiles(final Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException {
142 14ad7326 pastith
                if (folderId == null)
143 14ad7326 pastith
                        throw new ObjectNotFoundException("No folder specified");
144 cc154eca droutsis
                if (userId == null)
145 cc154eca droutsis
                        throw new ObjectNotFoundException("No user specified");
146 cc154eca droutsis
                User user = getEntityById(User.class, userId);
147 3d1b9329 koutsoub
                String query;
148 3d1b9329 koutsoub
                if(ignoreDeleted)
149 3d1b9329 koutsoub
                        query = "select f from FileHeader f where f.folder.id=:folderId  and f.deleted=false";
150 3d1b9329 koutsoub
                else
151 3d1b9329 koutsoub
                        query = "select f from FileHeader f where f.folder.id=:folderId";
152 cc154eca droutsis
                List<FileHeader> tempList = manager.createQuery(query).setParameter("folderId", folderId).getResultList();
153 cc154eca droutsis
                List<FileHeader> retv = new ArrayList<FileHeader>();
154 cc154eca droutsis
                for (FileHeader f: tempList)
155 cc154eca droutsis
                        if (f.hasReadPermission(user)) retv.add(f);
156 cc154eca droutsis
157 cc154eca droutsis
                return retv;
158 14ad7326 pastith
        }
159 14ad7326 pastith
160 023f6f1e Panagiotis Astithas
        @Override
161 14ad7326 pastith
        @SuppressWarnings("unchecked")
162 14ad7326 pastith
        public List<User> getUsers(final Long groupId) throws ObjectNotFoundException {
163 14ad7326 pastith
                if (groupId == null)
164 14ad7326 pastith
                        throw new ObjectNotFoundException("No group specified");
165 14ad7326 pastith
                return manager.createQuery("select u from User u join u.groupsMember g where g.id=:groupId").
166 14ad7326 pastith
                                setParameter("groupId", groupId).getResultList();
167 14ad7326 pastith
        }
168 14ad7326 pastith
169 14ad7326 pastith
        @Override
170 14ad7326 pastith
        public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException {
171 14ad7326 pastith
                if (parentId == null)
172 14ad7326 pastith
                        throw new ObjectNotFoundException("No parent folder specified");
173 14ad7326 pastith
                if (StringUtils.isEmpty(name))
174 14ad7326 pastith
                        throw new IllegalArgumentException("No folder name specified");
175 14ad7326 pastith
176 14ad7326 pastith
                try {
177 14ad7326 pastith
                        manager        .createQuery("select f from Folder f " +
178 14ad7326 pastith
                                        "where f.parent.id=:parentId and f.name=:name")
179 14ad7326 pastith
                                        .setParameter("parentId", parentId)
180 14ad7326 pastith
                                        .setParameter("name", name)
181 14ad7326 pastith
                                        .getSingleResult();
182 14ad7326 pastith
                        return true;
183 14ad7326 pastith
                } catch (NoResultException e) {
184 14ad7326 pastith
                        try {
185 14ad7326 pastith
                                manager        .createQuery("select f from FileHeader f " +
186 14ad7326 pastith
                                                "where f.folder.id=:parentId and f.name=:name")
187 14ad7326 pastith
                                                .setParameter("parentId", parentId)
188 14ad7326 pastith
                                                .setParameter("name", name)
189 14ad7326 pastith
                                                .getSingleResult();
190 14ad7326 pastith
                                return true;
191 14ad7326 pastith
                        } catch (NoResultException e1) {
192 14ad7326 pastith
                                return false;
193 14ad7326 pastith
                        }
194 14ad7326 pastith
                }
195 14ad7326 pastith
        }
196 14ad7326 pastith
197 023f6f1e Panagiotis Astithas
        @Override
198 14ad7326 pastith
        public boolean existsGroup(final Long userId, final String name) throws ObjectNotFoundException {
199 14ad7326 pastith
                if (userId == null)
200 14ad7326 pastith
                        throw new ObjectNotFoundException("No user specified");
201 14ad7326 pastith
                if (StringUtils.isEmpty(name))
202 14ad7326 pastith
                        throw new ObjectNotFoundException("No group name specified");
203 14ad7326 pastith
                try {
204 14ad7326 pastith
                        manager        .createQuery("select g from Group g where g.owner.id=:userId and g.name=:name")
205 14ad7326 pastith
                                        .setParameter("userId", userId)
206 14ad7326 pastith
                                        .setParameter("name", name)
207 14ad7326 pastith
                                        .getSingleResult();
208 14ad7326 pastith
                        return true;
209 14ad7326 pastith
                } catch (final NoResultException e) {
210 14ad7326 pastith
                        return false;
211 14ad7326 pastith
                }
212 14ad7326 pastith
        }
213 14ad7326 pastith
214 023f6f1e Panagiotis Astithas
        @Override
215 14ad7326 pastith
        public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException {
216 14ad7326 pastith
                if (userId == null)
217 14ad7326 pastith
                        throw new ObjectNotFoundException("No user specified");
218 14ad7326 pastith
                return new HashSet(manager.createQuery("select t.tag from FileTag t where t.user.id=:userId order by t.tag")
219 14ad7326 pastith
                                                .setParameter("userId", userId)
220 14ad7326 pastith
                                                .getResultList());
221 14ad7326 pastith
        }
222 14ad7326 pastith
223 023f6f1e Panagiotis Astithas
        @Override
224 14ad7326 pastith
        public void flush() {
225 14ad7326 pastith
                manager.flush();
226 14ad7326 pastith
        }
227 14ad7326 pastith
228 023f6f1e Panagiotis Astithas
        @Override
229 14ad7326 pastith
        public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException {
230 14ad7326 pastith
                if (folderId == null)
231 14ad7326 pastith
                        throw new ObjectNotFoundException("No parent folder specified");
232 14ad7326 pastith
                if (StringUtils.isEmpty(name))
233 14ad7326 pastith
                        throw new IllegalArgumentException("No file name specified");
234 14ad7326 pastith
235 14ad7326 pastith
                try {
236 14ad7326 pastith
                        return (FileHeader) manager.createQuery("select f from FileHeader f where f.folder.id=:parentId and f.name=:name")
237 14ad7326 pastith
                                        .setParameter("parentId", folderId)
238 14ad7326 pastith
                                        .setParameter("name", name)
239 14ad7326 pastith
                                        .getSingleResult();
240 14ad7326 pastith
                } catch (final NoResultException e1) {
241 14ad7326 pastith
                        throw new ObjectNotFoundException("File not found");
242 14ad7326 pastith
                }
243 14ad7326 pastith
        }
244 14ad7326 pastith
245 14ad7326 pastith
        @Override
246 14ad7326 pastith
        public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException {
247 14ad7326 pastith
                if (parentId == null)
248 14ad7326 pastith
                        throw new ObjectNotFoundException("No parent folder specified");
249 14ad7326 pastith
                if (StringUtils.isEmpty(name))
250 14ad7326 pastith
                        throw new IllegalArgumentException("No folder name specified");
251 14ad7326 pastith
252 14ad7326 pastith
                try {
253 14ad7326 pastith
                        return (Folder) manager.createQuery("select f from Folder f where f.parent.id=:parentId and f.name=:name")
254 14ad7326 pastith
                                        .setParameter("parentId", parentId)
255 14ad7326 pastith
                                        .setParameter("name", name)
256 14ad7326 pastith
                                        .getSingleResult();
257 14ad7326 pastith
                } catch (NoResultException e) {
258 14ad7326 pastith
                        throw new ObjectNotFoundException("Folder not found");
259 14ad7326 pastith
                }
260 14ad7326 pastith
        }
261 14ad7326 pastith
262 023f6f1e Panagiotis Astithas
        @Override
263 14ad7326 pastith
        public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException {
264 14ad7326 pastith
                if (userId == null)
265 14ad7326 pastith
                        throw new ObjectNotFoundException("No User specified");
266 cc154eca droutsis
                User user = getEntityById(User.class, userId);
267 14ad7326 pastith
268 cc154eca droutsis
                List<FileHeader> tempList = manager.createQuery("select f from FileHeader f where f.owner.id=:userId and " +
269 14ad7326 pastith
                                        "f.deleted=true and f.folder.deleted=false").
270 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
271 cc154eca droutsis
                List<FileHeader> retv = new ArrayList<FileHeader>();
272 cc154eca droutsis
                for (FileHeader f: tempList)
273 cc154eca droutsis
                        if (f.hasReadPermission(user)) retv.add(f);
274 cc154eca droutsis
275 cc154eca droutsis
                return retv;
276 14ad7326 pastith
        }
277 14ad7326 pastith
278 023f6f1e Panagiotis Astithas
        @Override
279 14ad7326 pastith
        public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException {
280 14ad7326 pastith
                if (userId == null)
281 14ad7326 pastith
                        throw new ObjectNotFoundException("No User specified");
282 14ad7326 pastith
                return manager.createQuery("select f from Folder f where f.owner.id=:userId and " +
283 14ad7326 pastith
                                        "f.deleted=true and f.parent.deleted=false").
284 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
285 14ad7326 pastith
        }
286 14ad7326 pastith
287 14ad7326 pastith
        @Override
288 14ad7326 pastith
        public User findUser(String username) {
289 14ad7326 pastith
                if (username == null)
290 14ad7326 pastith
                        return null;
291 14ad7326 pastith
                List<User> results = manager.createQuery("select u from User u where u.username=:username").
292 14ad7326 pastith
                                setParameter("username", username).getResultList();
293 14ad7326 pastith
                if (results.isEmpty()) return null;
294 14ad7326 pastith
                return results.get(0);
295 14ad7326 pastith
        }
296 14ad7326 pastith
297 3eaf782f pastith
        @Override
298 3eaf782f pastith
        public User findUserByEmail(String email) {
299 3eaf782f pastith
                if (email == null)
300 3eaf782f pastith
                        return null;
301 3eaf782f pastith
                List<User> results = manager.createQuery("select u from User u where u.email=:email").
302 3eaf782f pastith
                                setParameter("email", email).getResultList();
303 3eaf782f pastith
                if (results.isEmpty()) return null;
304 3eaf782f pastith
                return results.get(0);
305 3eaf782f pastith
        }
306 3eaf782f pastith
307 14ad7326 pastith
        @Override
308 14ad7326 pastith
        public List<User> getUsersByUserNameLike(String username) {
309 14ad7326 pastith
                return manager.createQuery("select u from User u where u.username like :username").
310 14ad7326 pastith
                setParameter("username", username+"%").getResultList();
311 14ad7326 pastith
        }
312 14ad7326 pastith
313 14ad7326 pastith
        @Override
314 14ad7326 pastith
        public List<Folder> getSharedRootFolders(Long userId) {
315 14ad7326 pastith
                List<Folder> folders = manager.createQuery("select distinct f from Folder f " +
316 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
317 dd127df7 Natasa Kapravelou
                                        "and (p.group.id != null or p.user.id != f.owner.id or f.readForAll=true) ").
318 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
319 14ad7326 pastith
                List<Folder> result = new ArrayList<Folder>();
320 14ad7326 pastith
                for(Folder f : folders)
321 14ad7326 pastith
                        if(!folders.contains(f.getParent()))
322 14ad7326 pastith
                                result.add(f);
323 14ad7326 pastith
                return result;
324 14ad7326 pastith
        }
325 14ad7326 pastith
326 14ad7326 pastith
        @Override
327 14ad7326 pastith
        public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) {
328 14ad7326 pastith
                return manager.createQuery("select distinct f from Folder f LEFT JOIN f.permissions p " +
329 14ad7326 pastith
                                        "where f.owner.id=:userId and f.deleted = false and p.group.id=:groupId ").
330 14ad7326 pastith
                                        setParameter("userId", userId).setParameter("groupId", groupId).getResultList();
331 14ad7326 pastith
        }
332 14ad7326 pastith
333 14ad7326 pastith
        @Override
334 14ad7326 pastith
        public List<User> getUsersSharingFoldersForUser(Long userId) {
335 14ad7326 pastith
                return manager.createQuery("select distinct f.owner from Folder f " +
336 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id != :userId and f.deleted=false " +
337 14ad7326 pastith
                                        "and (p.user.id=:userId or p.group.id in (select distinct gg.id " +
338 14ad7326 pastith
                                        "from Group gg join gg.members memb where memb.id=:userId))) ").
339 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
340 14ad7326 pastith
        }
341 14ad7326 pastith
342 14ad7326 pastith
        @Override
343 14ad7326 pastith
        public List<User> getUsersSharingFilesForUser(Long userId) {
344 14ad7326 pastith
                List<User> users = manager.createQuery("select distinct f.owner from FileHeader f " +
345 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id != :userId and f.deleted=false " +
346 14ad7326 pastith
                                        "and (p.user.id=:userId or p.group.id in (select distinct gg.id from Group gg " +
347 14ad7326 pastith
                                        "join gg.members memb where memb.id=:userId)))").
348 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
349 14ad7326 pastith
                return users;
350 14ad7326 pastith
351 14ad7326 pastith
        }
352 14ad7326 pastith
353 14ad7326 pastith
        @Override
354 cc154eca droutsis
        public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException {
355 cc154eca droutsis
                if (userId == null)
356 cc154eca droutsis
                        throw new ObjectNotFoundException("No user specified");
357 cc154eca droutsis
                User user = getEntityById(User.class, userId);
358 cc154eca droutsis
                List<FileHeader> tempList = manager.createQuery("select distinct f from FileHeader f " +
359 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
360 b4c3f47a pastith
                                        "and (f.readForAll=true or p.group.id != null or p.user.id != f.owner.id)" +
361 b4c3f47a pastith
                                        " and f.folder.id not in (select distinct fo.id from Folder fo LEFT JOIN " +
362 b4c3f47a pastith
                                        "fo.permissions po where fo.owner.id=:userId and fo.deleted=false and " +
363 749c03f9 Natasa Kapravelou
                                        "(po.group.id != null or po.user.id != fo.owner.id or fo.readForAll = true))").
364 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
365 cc154eca droutsis
                List<FileHeader> retv = new ArrayList<FileHeader>();
366 cc154eca droutsis
                for (FileHeader f: tempList)
367 cc154eca droutsis
                        if (f.hasReadPermission(user)) retv.add(f);
368 cc154eca droutsis
369 cc154eca droutsis
                return retv;
370 14ad7326 pastith
        }
371 14ad7326 pastith
372 14ad7326 pastith
        @Override
373 cc154eca droutsis
        public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException {
374 cc154eca droutsis
                if (userId == null)
375 cc154eca droutsis
                        throw new ObjectNotFoundException("No user specified");
376 cc154eca droutsis
                User user = getEntityById(User.class, userId);
377 cc154eca droutsis
                List<FileHeader> tempList = manager.createQuery("select distinct f from FileHeader f " +
378 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
379 14ad7326 pastith
                                        "and (p.group.id != null or p.user.id != f.owner.id)").
380 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
381 cc154eca droutsis
                List<FileHeader> retv = new ArrayList<FileHeader>();
382 cc154eca droutsis
                for (FileHeader f: tempList)
383 cc154eca droutsis
                        if (f.hasReadPermission(user)) retv.add(f);
384 cc154eca droutsis
385 cc154eca droutsis
                return retv;
386 14ad7326 pastith
        }
387 14ad7326 pastith
388 14ad7326 pastith
        @Override
389 14ad7326 pastith
        public List<Folder> getSharedFolders(Long userId) {
390 14ad7326 pastith
                List<Folder> folders = manager.createQuery("select distinct f from Folder f " +
391 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
392 14ad7326 pastith
                                        "and (p.group.id != null or p.user.id != f.owner.id)").
393 14ad7326 pastith
                                        setParameter("userId", userId).getResultList();
394 14ad7326 pastith
                return folders;
395 14ad7326 pastith
        }
396 14ad7326 pastith
397 14ad7326 pastith
        @Override
398 cc154eca droutsis
        public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException {
399 cc154eca droutsis
                if (userId == null)
400 cc154eca droutsis
                        throw new ObjectNotFoundException("No user specified");
401 cc154eca droutsis
                User user = getEntityById(User.class, userId);
402 cc154eca droutsis
                List<FileHeader> tempList = manager.createQuery("select distinct f from FileHeader f " +
403 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
404 14ad7326 pastith
                                        "and p.read=true and (p.user.id=:cuserId or p.group.id in " +
405 14ad7326 pastith
                                        "(select distinct gg.id from Group gg join gg.members memb " +
406 14ad7326 pastith
                                        "where memb.id=:cuserId)) and f.folder.id not in (select distinct fo.id " +
407 14ad7326 pastith
                                        "from Folder fo LEFT JOIN fo.permissions po where fo.owner.id = :userId " +
408 14ad7326 pastith
                                        "and fo.deleted=false and po.read=true and (po.user.id=:cuserId " +
409 14ad7326 pastith
                                        "or po.group.id in (select distinct ggo.id from Group ggo " +
410 14ad7326 pastith
                                        "join ggo.members membo where membo.id=:cuserId)))").
411 14ad7326 pastith
                                        setParameter("userId", userId).setParameter("cuserId", callingUserId).getResultList();
412 cc154eca droutsis
                List<FileHeader> retv = new ArrayList<FileHeader>();
413 cc154eca droutsis
                for (FileHeader f: tempList)
414 cc154eca droutsis
                        if (f.hasReadPermission(user)) retv.add(f);
415 cc154eca droutsis
416 cc154eca droutsis
                return retv;
417 14ad7326 pastith
        }
418 14ad7326 pastith
419 14ad7326 pastith
        @Override
420 14ad7326 pastith
        public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) {
421 14ad7326 pastith
                List<Folder> folders = manager.createQuery("select distinct f from Folder f " +
422 14ad7326 pastith
                                        "LEFT JOIN f.permissions p where f.owner.id = :userId and f.deleted=false " +
423 14ad7326 pastith
                                        "and p.read=true and (p.user.id=:cuserId or p.group.id in " +
424 14ad7326 pastith
                                        "(select distinct gg.id from Group gg join gg.members memb " +
425 14ad7326 pastith
                                        "where memb.id=:cuserId))) ").
426 14ad7326 pastith
                                        setParameter("userId", userId).
427 14ad7326 pastith
                                        setParameter("cuserId", callingUserId).
428 14ad7326 pastith
                                        getResultList();
429 14ad7326 pastith
                List<Folder> result = new ArrayList<Folder>();
430 14ad7326 pastith
                for(Folder f : folders)
431 14ad7326 pastith
                        if(!folders.contains(f.getParent()))
432 14ad7326 pastith
                                result.add(f);
433 14ad7326 pastith
                return result;
434 14ad7326 pastith
435 14ad7326 pastith
        }
436 14ad7326 pastith
437 14ad7326 pastith
        @Override
438 14ad7326 pastith
        public List<FileHeader> searchFiles(Long userId, String query) {
439 14ad7326 pastith
                return manager.createQuery("select f from FileHeader f where f.owner.id=:userId and f.name like :query").
440 14ad7326 pastith
                                setParameter("query", "%"+query+"%").setParameter("userId",userId).getResultList();
441 14ad7326 pastith
        }
442 14ad7326 pastith
443 14ad7326 pastith
        @Override
444 14ad7326 pastith
        public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException {
445 14ad7326 pastith
                List<Nonce> results = manager.createQuery("select n from Nonce n where n.userId=:userId and n.encodedNonce=:nonce").
446 14ad7326 pastith
                                setParameter("userId", userId).setParameter("nonce", nonce).getResultList();
447 14ad7326 pastith
                if (results.isEmpty())
448 14ad7326 pastith
                        throw new ObjectNotFoundException("No nonce found");
449 14ad7326 pastith
                return results.get(0);
450 14ad7326 pastith
        }
451 14ad7326 pastith
452 14ad7326 pastith
        @Override
453 14ad7326 pastith
        public Long getFileCount(Long userId) {
454 14ad7326 pastith
                Long singleResult = (Long) manager.createQuery("select count(f) from FileHeader f where f.owner.id=:ownerId")
455 14ad7326 pastith
                .setParameter("ownerId", userId)
456 14ad7326 pastith
                .getSingleResult();
457 14ad7326 pastith
                return singleResult;
458 14ad7326 pastith
        }
459 14ad7326 pastith
460 14ad7326 pastith
        @Override
461 14ad7326 pastith
        public Long getFileSize(Long userId) {
462 14ad7326 pastith
                Long singleResult = (Long) manager.createQuery("select sum(f.fileSize) from FileBody f where f.header.owner.id=:ownerId")
463 14ad7326 pastith
                .setParameter("ownerId", userId)
464 14ad7326 pastith
                .getSingleResult();
465 14ad7326 pastith
                if(singleResult == null)
466 14ad7326 pastith
                        singleResult = new Long(0L);
467 14ad7326 pastith
                return singleResult;
468 14ad7326 pastith
469 14ad7326 pastith
        }
470 14ad7326 pastith
471 14ad7326 pastith
        @Override
472 14ad7326 pastith
        public List<Long> getAllFileIds() {
473 14ad7326 pastith
                List<Long> ids = manager.createQuery("select f.id from FileHeader f").getResultList();
474 14ad7326 pastith
                return ids;
475 14ad7326 pastith
        }
476 14ad7326 pastith
477 14ad7326 pastith
        @Override
478 14ad7326 pastith
        public FileUploadStatus getFileUploadStatus(Long userId, String fileName) {
479 14ad7326 pastith
                List<FileUploadStatus> res = manager.createQuery(" select f from FileUploadStatus f where f.owner.id=:userId and f.filename=:filename").setParameter("userId", userId).setParameter("filename", fileName).getResultList();
480 14ad7326 pastith
                if(res.size()>0)
481 14ad7326 pastith
                        return res.get(0);
482 14ad7326 pastith
                return null;
483 14ad7326 pastith
        }
484 14ad7326 pastith
485 14ad7326 pastith
        @Override
486 14ad7326 pastith
        public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException {
487 14ad7326 pastith
                try {
488 14ad7326 pastith
                        return (FileBody) manager.createQuery("select f from FileBody f " +
489 14ad7326 pastith
                        "where f.header.id=:fileId and f.version=:version")
490 14ad7326 pastith
                        .setParameter("fileId", fileId).setParameter("version", version)
491 14ad7326 pastith
                        .getSingleResult();
492 14ad7326 pastith
                } catch (NoResultException e) {
493 14ad7326 pastith
                        throw new ObjectNotFoundException("No version " + version + " found for file #" + fileId);
494 14ad7326 pastith
                }
495 14ad7326 pastith
        }
496 8f128261 droutsis
497 8f128261 droutsis
        @Override
498 8f128261 droutsis
        public void updateAccounting(User user, Date date, long bandwidthDiff) {
499 8f128261 droutsis
                AccountingInfo ai = null;
500 8f128261 droutsis
                try {
501 8f128261 droutsis
                        ai = (AccountingInfo) manager.createQuery("select ai from AccountingInfo ai " +
502 8f128261 droutsis
                                "where ai.user=:user and ai.dateFrom<=:date and ai.dateTo>:date")
503 8f128261 droutsis
                                .setParameter("user", user)
504 8f128261 droutsis
                                .setParameter("date", date)
505 8f128261 droutsis
                                .getSingleResult();
506 8f128261 droutsis
                }
507 8f128261 droutsis
                catch (NoResultException e) {
508 8f128261 droutsis
                        ai = null;
509 8f128261 droutsis
                }
510 8f128261 droutsis
511 8f128261 droutsis
                if (ai==null) {
512 8f128261 droutsis
                        // The right entry does not exist; must be created.
513 8f128261 droutsis
                        // This is where we set the initial time period.
514 8f128261 droutsis
                        // We now start from the user's creation, we can change this to something else.
515 8f128261 droutsis
                        Calendar creationDate = new GregorianCalendar();
516 8f128261 droutsis
                        creationDate.setTime(user.getAuditInfo().getCreationDate());
517 8f128261 droutsis
                        int offset = 0;
518 8f128261 droutsis
                        Calendar dateFrom;
519 8f128261 droutsis
                        Calendar dateTo;
520 8f128261 droutsis
                        long timeInMillis = date.getTime();
521 8f128261 droutsis
                        do {
522 8f128261 droutsis
                                dateFrom = (Calendar) creationDate.clone();
523 8f128261 droutsis
                                dateFrom.add(BANDWIDTH_TIME_PERIOD_FIELD, offset);
524 8f128261 droutsis
                                dateTo = (Calendar) dateFrom.clone();
525 8f128261 droutsis
                                dateTo.add(BANDWIDTH_TIME_PERIOD_FIELD, 1);
526 8f128261 droutsis
                                offset += BANDWIDTH_TIME_PERIOD_AMOUNT;
527 8f128261 droutsis
                        }
528 8f128261 droutsis
                        while (!(dateFrom.getTimeInMillis()<=timeInMillis && dateTo.getTimeInMillis()>timeInMillis));
529 8f128261 droutsis
530 8f128261 droutsis
                        ai = new AccountingInfo(user, dateFrom.getTime(), dateTo.getTime());
531 8f128261 droutsis
                        manager.persist(ai);
532 8f128261 droutsis
                }
533 8f128261 droutsis
534 8f128261 droutsis
                // Do the update.
535 8f128261 droutsis
                ai.updateBandwidth(bandwidthDiff);
536 8f128261 droutsis
        }
537 8f128261 droutsis
538 82248972 Panagiotis Astithas
        @Override
539 023f6f1e Panagiotis Astithas
        public List<UserClass> getUserClasses() {
540 023f6f1e Panagiotis Astithas
                // Ordering by quota is important here.
541 023f6f1e Panagiotis Astithas
                List<UserClass> ids = manager.createQuery("select uc from UserClass uc order by uc.quota").getResultList();
542 023f6f1e Panagiotis Astithas
                return ids;
543 023f6f1e Panagiotis Astithas
        }
544 023f6f1e Panagiotis Astithas
545 023f6f1e Panagiotis Astithas
        @Override
546 023f6f1e Panagiotis Astithas
        public List<User> getUsersByUserNameOrEmailLike(String query) {
547 023f6f1e Panagiotis Astithas
                return manager.createQuery("select u from User u where " +
548 023f6f1e Panagiotis Astithas
                                        " upper(u.username) like :query or upper(u.email) like :query order by u.username").
549 023f6f1e Panagiotis Astithas
                        setParameter("query", query.toUpperCase()+"%").getResultList();
550 023f6f1e Panagiotis Astithas
        }
551 023f6f1e Panagiotis Astithas
552 023f6f1e Panagiotis Astithas
        @Override
553 82248972 Panagiotis Astithas
        public Invitation findInvite(String code) {
554 82248972 Panagiotis Astithas
                if (code == null)
555 82248972 Panagiotis Astithas
                        return null;
556 82248972 Panagiotis Astithas
                List<Invitation> results = manager.createQuery("select i from Invitation i where i.code=:code").
557 82248972 Panagiotis Astithas
                                setParameter("code", code).getResultList();
558 82248972 Panagiotis Astithas
                if (results.isEmpty()) return null;
559 82248972 Panagiotis Astithas
                return results.get(0);
560 82248972 Panagiotis Astithas
        }
561 82248972 Panagiotis Astithas
562 01a30cd0 Panagiotis Astithas
        @Override
563 01a30cd0 Panagiotis Astithas
        public UserClass findCouponUserClass() {
564 01a30cd0 Panagiotis Astithas
                List<UserClass> results = manager.createQuery("select uc from UserClass uc where uc.name=:name").
565 01a30cd0 Panagiotis Astithas
                                setParameter("name", getConfiguration().getString("couponQuota")).getResultList();
566 01a30cd0 Panagiotis Astithas
                if (results.isEmpty()) {
567 01a30cd0 Panagiotis Astithas
                        // Create the coupon user class on first use.
568 01a30cd0 Panagiotis Astithas
                        UserClass couponClass = new UserClass();
569 01a30cd0 Panagiotis Astithas
                        couponClass.setName("coupon");
570 01a30cd0 Panagiotis Astithas
                        Long couponQuota = getConfiguration().getLong("couponQuota", new Long(52428800L));
571 01a30cd0 Panagiotis Astithas
                        couponClass.setQuota(couponQuota);
572 01a30cd0 Panagiotis Astithas
                        create(couponClass);
573 01a30cd0 Panagiotis Astithas
                        flush();
574 01a30cd0 Panagiotis Astithas
                        results.add(couponClass);
575 01a30cd0 Panagiotis Astithas
                }
576 01a30cd0 Panagiotis Astithas
                return results.get(0);
577 01a30cd0 Panagiotis Astithas
        }
578 023f6f1e Panagiotis Astithas
579 023f6f1e Panagiotis Astithas
        @Override
580 023f6f1e Panagiotis Astithas
        public Long getFileCount(UserClass userClass) {
581 023f6f1e Panagiotis Astithas
                Long result;
582 023f6f1e Panagiotis Astithas
                if(userClass==null)
583 023f6f1e Panagiotis Astithas
                        result=(Long) manager.createQuery("select count(f) from FileHeader f").getSingleResult();
584 023f6f1e Panagiotis Astithas
                else result= (Long) manager.createQuery("select count(f) from FileHeader f where f.owner.userClass.id=:id").setParameter("id", userClass.getId()).getSingleResult();
585 023f6f1e Panagiotis Astithas
                if(result==null)
586 023f6f1e Panagiotis Astithas
                        result =0L;
587 023f6f1e Panagiotis Astithas
                return result;
588 023f6f1e Panagiotis Astithas
        }
589 023f6f1e Panagiotis Astithas
590 023f6f1e Panagiotis Astithas
        @Override
591 023f6f1e Panagiotis Astithas
        public Long getFileSize(UserClass userClass) {
592 023f6f1e Panagiotis Astithas
                Long result;
593 023f6f1e Panagiotis Astithas
                if(userClass==null)
594 023f6f1e Panagiotis Astithas
                        result=(Long) manager.createQuery("select sum(f.currentBody.fileSize) from FileHeader f").getSingleResult();
595 023f6f1e Panagiotis Astithas
                else result=(Long) manager.createQuery("select sum(f.currentBody.fileSize) from FileHeader f where f.owner.userClass.id=:id").setParameter("id", userClass.getId()).getSingleResult();
596 023f6f1e Panagiotis Astithas
                if(result==null)
597 023f6f1e Panagiotis Astithas
                        result =0L;
598 023f6f1e Panagiotis Astithas
                return result;
599 023f6f1e Panagiotis Astithas
        }
600 023f6f1e Panagiotis Astithas
601 023f6f1e Panagiotis Astithas
        @Override
602 023f6f1e Panagiotis Astithas
        public Long getUserCount(UserClass userClass) {
603 023f6f1e Panagiotis Astithas
                Long result;
604 023f6f1e Panagiotis Astithas
                if(userClass==null)
605 023f6f1e Panagiotis Astithas
                        result = (Long) manager.createQuery("select count(u) from User u").getSingleResult();
606 023f6f1e Panagiotis Astithas
                else result = (Long) manager.createQuery("select count(u) from User u where u.userClass.id=:id").setParameter("id", userClass.getId()).getSingleResult();
607 023f6f1e Panagiotis Astithas
                if(result==null)
608 023f6f1e Panagiotis Astithas
                        result =0L;
609 023f6f1e Panagiotis Astithas
                return result;
610 023f6f1e Panagiotis Astithas
        }
611 023f6f1e Panagiotis Astithas
612 023f6f1e Panagiotis Astithas
        @Override
613 023f6f1e Panagiotis Astithas
        public Long getCountUsersByLastLogin(Date lastLoginDate) {
614 023f6f1e Panagiotis Astithas
                return (Long) manager.createQuery("select count(u) from User u where " +
615 023f6f1e Panagiotis Astithas
                " u.lastLogin >= :ldate ").setParameter("ldate", lastLoginDate).getSingleResult();
616 023f6f1e Panagiotis Astithas
        }
617 023f6f1e Panagiotis Astithas
618 023f6f1e Panagiotis Astithas
        @Override
619 023f6f1e Panagiotis Astithas
        public List<User> getUsersByLastLogin(Date lastLoginDate) {
620 023f6f1e Panagiotis Astithas
                return manager.createQuery("select u from User u where " +
621 023f6f1e Panagiotis Astithas
                        " u.lastLogin >= :ldate order by u.lastLogin desc").
622 023f6f1e Panagiotis Astithas
                        setParameter("ldate", lastLoginDate).getResultList();
623 023f6f1e Panagiotis Astithas
        }
624 023f6f1e Panagiotis Astithas
625 023f6f1e Panagiotis Astithas
        @Override
626 023f6f1e Panagiotis Astithas
        public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult) {
627 023f6f1e Panagiotis Astithas
                return manager.createQuery("select u from User u where " +
628 023f6f1e Panagiotis Astithas
                " u.lastLogin >= :ldate order by u.lastLogin desc").
629 023f6f1e Panagiotis Astithas
                setParameter("ldate", lastLoginDate).setFirstResult(firstResult).setMaxResults(maxResult).getResultList();
630 023f6f1e Panagiotis Astithas
        }
631 023f6f1e Panagiotis Astithas
632 023f6f1e Panagiotis Astithas
        @Override
633 023f6f1e Panagiotis Astithas
        public List<User> getInactiveUsers() {
634 023f6f1e Panagiotis Astithas
                return manager.createQuery("select u from User u where u.active=:active").setParameter("active", false).getResultList();
635 023f6f1e Panagiotis Astithas
        }
636 023f6f1e Panagiotis Astithas
637 023f6f1e Panagiotis Astithas
        @Override
638 023f6f1e Panagiotis Astithas
        public List<FileHeader> searchFileByFilename(String filename) {
639 023f6f1e Panagiotis Astithas
                return manager.createQuery("select f from FileHeader f where f.name=:name").setParameter("name", filename).getResultList();
640 023f6f1e Panagiotis Astithas
        }
641 023f6f1e Panagiotis Astithas
642 023f6f1e Panagiotis Astithas
        @Override
643 023f6f1e Panagiotis Astithas
        public Long getBandwithUsed(UserClass userClass, Date date) {
644 023f6f1e Panagiotis Astithas
                Long result;
645 023f6f1e Panagiotis Astithas
                if (userClass == null)
646 023f6f1e Panagiotis Astithas
                        result = (Long) manager.createQuery("select sum(ai.bandwidthUsed)" +
647 023f6f1e Panagiotis Astithas
                                        " from AccountingInfo ai where ai.dateFrom<=:date and " +
648 023f6f1e Panagiotis Astithas
                                        "ai.dateTo>:date").
649 023f6f1e Panagiotis Astithas
                                        setParameter("date", date).
650 023f6f1e Panagiotis Astithas
                                        getSingleResult();
651 023f6f1e Panagiotis Astithas
                else
652 023f6f1e Panagiotis Astithas
                        result = (Long) manager.createQuery("select sum(ai.bandwidthUsed)" +
653 023f6f1e Panagiotis Astithas
                                        " from AccountingInfo ai where ai.user.userClass.id=:id " +
654 023f6f1e Panagiotis Astithas
                                        "and ai.dateFrom<=:date and ai.dateTo>:date").
655 023f6f1e Panagiotis Astithas
                                        setParameter("date", date).
656 023f6f1e Panagiotis Astithas
                                        setParameter("id", userClass.getId()).
657 023f6f1e Panagiotis Astithas
                                        getSingleResult();
658 023f6f1e Panagiotis Astithas
                if (result == null)
659 023f6f1e Panagiotis Astithas
                        result = 0L;
660 023f6f1e Panagiotis Astithas
                return result;
661 023f6f1e Panagiotis Astithas
        }
662 023f6f1e Panagiotis Astithas
663 023f6f1e Panagiotis Astithas
        @Override
664 023f6f1e Panagiotis Astithas
        public List<AccountingInfo> getAccountingInfo(User user) {
665 023f6f1e Panagiotis Astithas
                List<AccountingInfo> ai = new ArrayList<AccountingInfo>();
666 023f6f1e Panagiotis Astithas
                try {
667 023f6f1e Panagiotis Astithas
                        ai =  manager.createQuery("select ai from AccountingInfo ai " +
668 023f6f1e Panagiotis Astithas
                                "where ai.user=:user")
669 023f6f1e Panagiotis Astithas
                                .setParameter("user", user)
670 023f6f1e Panagiotis Astithas
                                .getResultList();
671 023f6f1e Panagiotis Astithas
                }
672 023f6f1e Panagiotis Astithas
                catch (NoResultException e) {}
673 023f6f1e Panagiotis Astithas
                return ai;
674 023f6f1e Panagiotis Astithas
        }
675 023f6f1e Panagiotis Astithas
676 023f6f1e Panagiotis Astithas
        @Override
677 023f6f1e Panagiotis Astithas
        public AccountingInfo getAccountingInfo(User user, Date date) {
678 023f6f1e Panagiotis Astithas
                AccountingInfo ai = null;
679 023f6f1e Panagiotis Astithas
                try {
680 023f6f1e Panagiotis Astithas
                        ai = (AccountingInfo) manager.createQuery("select ai from AccountingInfo ai " +
681 023f6f1e Panagiotis Astithas
                                "where ai.user=:user and ai.dateFrom<=:date and ai.dateTo>:date")
682 023f6f1e Panagiotis Astithas
                                .setParameter("user", user)
683 023f6f1e Panagiotis Astithas
                                .setParameter("date", date)
684 023f6f1e Panagiotis Astithas
                                .getSingleResult();
685 023f6f1e Panagiotis Astithas
                }
686 023f6f1e Panagiotis Astithas
                catch (NoResultException e) {
687 023f6f1e Panagiotis Astithas
                        // If not found, that means that there is no accounting info noted
688 023f6f1e Panagiotis Astithas
                        // for given time. So return a 0 as an answer.
689 023f6f1e Panagiotis Astithas
                        ai = new AccountingInfo(user, date, date);
690 023f6f1e Panagiotis Astithas
                }
691 023f6f1e Panagiotis Astithas
                return ai;
692 023f6f1e Panagiotis Astithas
        }
693 b7565ade Natasa Kapravelou
694 b7565ade Natasa Kapravelou
        @Override
695 b7565ade Natasa Kapravelou
        public List<FileHeader> getFilesPermittedForGroup(Long userId, Long groupId) {
696 b7565ade Natasa Kapravelou
                return manager.createQuery("select distinct f from FileHeader f LEFT JOIN f.permissions p " +
697 b7565ade Natasa Kapravelou
                                        "where f.owner.id=:userId and f.deleted = false and p.group.id=:groupId ").
698 b7565ade Natasa Kapravelou
                                        setParameter("userId", userId).setParameter("groupId", groupId).getResultList();
699 b7565ade Natasa Kapravelou
        }
700 376d0ebf Christos V. Stathis
701 376d0ebf Christos V. Stathis
    @Override
702 376d0ebf Christos V. Stathis
    public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException {
703 376d0ebf Christos V. Stathis
        FileHeader h = getEntityById(FileHeader.class, id);
704 376d0ebf Christos V. Stathis
        h.getFileTags().size();
705 376d0ebf Christos V. Stathis
        return h;
706 376d0ebf Christos V. Stathis
    }
707 14ad7326 pastith
}