2 * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server.ejb;
21 import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
22 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
23 import gr.ebs.gss.server.domain.AccountingInfo;
24 import gr.ebs.gss.server.domain.FileBody;
25 import gr.ebs.gss.server.domain.FileHeader;
26 import gr.ebs.gss.server.domain.FileUploadStatus;
27 import gr.ebs.gss.server.domain.Folder;
28 import gr.ebs.gss.server.domain.Group;
29 import gr.ebs.gss.server.domain.Invitation;
30 import gr.ebs.gss.server.domain.Nonce;
31 import gr.ebs.gss.server.domain.User;
32 import gr.ebs.gss.server.domain.UserClass;
33 import gr.ebs.gss.server.domain.UserLogin;
35 import java.math.BigInteger;
36 import java.util.ArrayList;
37 import java.util.Calendar;
38 import java.util.Date;
39 import java.util.GregorianCalendar;
40 import java.util.HashSet;
41 import java.util.List;
44 import javax.ejb.Stateless;
45 import javax.persistence.EntityManager;
46 import javax.persistence.NoResultException;
47 import javax.persistence.PersistenceContext;
48 import javax.persistence.Query;
50 import org.apache.commons.lang.StringUtils;
53 * The implementation of the GSSDAO interface.
56 public class GSSDAOBean implements GSSDAO {
58 private static final int BANDWIDTH_TIME_PERIOD_FIELD = Calendar.MONTH;
59 private static final int BANDWIDTH_TIME_PERIOD_AMOUNT = 1;
62 * The entity manager for the persistence unit
64 @PersistenceContext(unitName = "gss")
65 private EntityManager manager;
68 public Folder getRootFolder(final Long userId) throws ObjectNotFoundException {
71 throw new ObjectNotFoundException("No user specified");
72 return (Folder) manager .createQuery("select f from Folder f where f.owner.id=:ownerId and f.parent is null")
73 .setParameter("ownerId", userId)
75 } catch (final NoResultException e) {
76 throw new ObjectNotFoundException("Root folder not found for user with id=" + userId);
81 public User getUser(final String username) throws ObjectNotFoundException {
84 throw new ObjectNotFoundException("No user specified");
85 return (User) manager .createQuery("select f from User f where f.username=:username")
86 .setParameter("username", username)
88 } catch (final NoResultException e) {
89 throw new ObjectNotFoundException("No User found for username=" + username);
94 public void create(final Object obj) {
96 throw new IllegalArgumentException("No object speficied");
101 public void refresh(final Object obj) {
103 throw new IllegalArgumentException("No object speficied");
104 manager.refresh(obj);
108 public void update(final Object obj) {
110 throw new IllegalArgumentException("No object speficied");
115 public void delete(final Object entity) {
117 throw new IllegalArgumentException("No object speficied");
118 manager.remove(entity);
122 public <T> T getEntityById(final Class<T> _class, final Object _id) throws ObjectNotFoundException {
124 throw new ObjectNotFoundException("No " + _class.getSimpleName() + " specified");
126 final T entity = manager.find(_class, _id);
128 throw new ObjectNotFoundException(_class.getSimpleName() + " with id=" + _id + " was not found");
134 @SuppressWarnings("unchecked")
135 public List<Group> getGroups(final Long userId) throws ObjectNotFoundException {
137 throw new ObjectNotFoundException("No user specified");
139 return manager.createQuery("select g from Group g where g.owner.id=:userId").setParameter("userId", userId).getResultList();
143 @SuppressWarnings("unchecked")
144 public List<FileHeader> getFiles(final Long folderId, Long userId, boolean ignoreDeleted) throws ObjectNotFoundException {
145 if (folderId == null)
146 throw new ObjectNotFoundException("No folder specified");
148 throw new ObjectNotFoundException("No user specified");
149 User user = getEntityById(User.class, userId);
152 query = "select f from FileHeader f where f.folder.id=:folderId and f.deleted=false";
154 query = "select f from FileHeader f where f.folder.id=:folderId";
155 List<FileHeader> tempList = manager.createQuery(query).setParameter("folderId", folderId).getResultList();
156 List<FileHeader> retv = new ArrayList<FileHeader>();
157 for (FileHeader f: tempList)
158 if (f.hasReadPermission(user)) retv.add(f);
164 @SuppressWarnings("unchecked")
165 public List<User> getUsers(final Long groupId) throws ObjectNotFoundException {
167 throw new ObjectNotFoundException("No group specified");
168 return manager.createQuery("select u from User u join u.groupsMember g where g.id=:groupId").
169 setParameter("groupId", groupId).getResultList();
173 public boolean existsFolderOrFile(Long parentId, String name) throws ObjectNotFoundException {
174 if (parentId == null)
175 throw new ObjectNotFoundException("No parent folder specified");
176 if (StringUtils.isEmpty(name))
177 throw new IllegalArgumentException("No folder name specified");
180 manager .createQuery("select f from Folder f " +
181 "where f.parent.id=:parentId and f.name=:name")
182 .setParameter("parentId", parentId)
183 .setParameter("name", name)
186 } catch (NoResultException e) {
188 manager .createQuery("select f from FileHeader f " +
189 "where f.folder.id=:parentId and f.name=:name")
190 .setParameter("parentId", parentId)
191 .setParameter("name", name)
194 } catch (NoResultException e1) {
201 public boolean existsGroup(final Long userId, final String name) throws ObjectNotFoundException {
203 throw new ObjectNotFoundException("No user specified");
204 if (StringUtils.isEmpty(name))
205 throw new ObjectNotFoundException("No group name specified");
207 manager .createQuery("select g from Group g where g.owner.id=:userId and g.name=:name")
208 .setParameter("userId", userId)
209 .setParameter("name", name)
212 } catch (final NoResultException e) {
218 public Set<String> getUserTags(final Long userId) throws ObjectNotFoundException {
220 throw new ObjectNotFoundException("No user specified");
221 return new HashSet(manager.createQuery("select t.tag from FileTag t where t.user.id=:userId order by t.tag")
222 .setParameter("userId", userId)
227 public void flush() {
232 public FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException {
233 if (folderId == null)
234 throw new ObjectNotFoundException("No parent folder specified");
235 if (StringUtils.isEmpty(name))
236 throw new IllegalArgumentException("No file name specified");
239 return (FileHeader) manager.createQuery("select f from FileHeader f where f.folder.id=:parentId and f.name=:name")
240 .setParameter("parentId", folderId)
241 .setParameter("name", name)
243 } catch (final NoResultException e1) {
244 throw new ObjectNotFoundException("File not found");
249 public Folder getFolder(Long parentId, String name) throws ObjectNotFoundException {
250 if (parentId == null)
251 throw new ObjectNotFoundException("No parent folder specified");
252 if (StringUtils.isEmpty(name))
253 throw new IllegalArgumentException("No folder name specified");
256 return (Folder) manager.createQuery("select f from Folder f where f.parent.id=:parentId and f.name=:name")
257 .setParameter("parentId", parentId)
258 .setParameter("name", name)
260 } catch (NoResultException e) {
261 throw new ObjectNotFoundException("Folder not found");
266 public List<FileHeader> getDeletedFiles(Long userId) throws ObjectNotFoundException {
268 throw new ObjectNotFoundException("No User specified");
269 User user = getEntityById(User.class, userId);
271 List<FileHeader> tempList = manager.createQuery("select f from FileHeader f where f.owner.id=:userId and " +
272 "f.deleted=true and f.folder.deleted=false").
273 setParameter("userId", userId).getResultList();
274 List<FileHeader> retv = new ArrayList<FileHeader>();
275 for (FileHeader f: tempList)
276 if (f.hasReadPermission(user)) retv.add(f);
282 public List<Folder> getDeletedRootFolders(Long userId) throws ObjectNotFoundException {
284 throw new ObjectNotFoundException("No User specified");
285 return manager.createQuery("select f from Folder f where f.owner.id=:userId and " +
286 "f.deleted=true and f.parent.deleted=false").
287 setParameter("userId", userId).getResultList();
291 public User findUser(String username) {
292 if (username == null)
294 List<User> results = manager.createQuery("select u from User u where u.username=:username").
295 setParameter("username", username).getResultList();
296 if (results.isEmpty()) return null;
297 return results.get(0);
301 public User findUserByEmail(String email) {
304 List<User> results = manager.createQuery("select u from User u where u.email=:email").
305 setParameter("email", email).getResultList();
306 if (results.isEmpty()) return null;
307 return results.get(0);
311 public List<User> getUsersByUserNameLike(String username) {
312 return manager.createQuery("select u from User u where u.username like :username").
313 setParameter("username", username+"%").getResultList();
317 public List<Folder> getSharedRootFolders(Long userId) {
318 List<Folder> folders = manager.createQuery("select distinct f from Folder f " +
319 "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
320 "and (p.group.id != null or p.user.id != f.owner.id or f.readForAll=true) ").
321 setParameter("userId", userId).getResultList();
322 List<Folder> result = new ArrayList<Folder>();
323 for(Folder f : folders)
324 if(!folders.contains(f.getParent()))
330 public List<Folder> getFoldersPermittedForGroup(Long userId, Long groupId) {
331 return manager.createQuery("select distinct f from Folder f LEFT JOIN f.permissions p " +
332 "where f.owner.id=:userId and f.deleted = false and p.group.id=:groupId ").
333 setParameter("userId", userId).setParameter("groupId", groupId).getResultList();
336 private List<Long> getGroupIdsForUserId(Long userId) {
337 List<BigInteger> groups = manager.createNativeQuery("select distinct groupsmember_id " +
338 "from GSS_Group_GSS_User where members_id=:userId")
339 .setParameter("userId", userId)
341 List<Long> groupIds = new ArrayList<Long>();
342 for (BigInteger id : groups)
343 groupIds.add(id.longValue());
348 public List<User> getUsersSharingFoldersForUser(Long userId) {
349 List<Long> groupIds = getGroupIdsForUserId(userId);
350 Query q = manager.createQuery("select distinct f.owner from Folder f " +
351 "LEFT JOIN f.permissions p where f.owner.id != :userId and f.deleted=false " +
352 "and (p.user.id=:userId "+ (groupIds.isEmpty() ? "" : "or p.group.id in (:groupIds)") +")").
353 setParameter("userId", userId);
354 if (!groupIds.isEmpty())
355 q.setParameter("groupIds", groupIds);
356 return q.getResultList();
360 public List<User> getUsersSharingFilesForUser(Long userId) {
361 List<Long> groupIds = getGroupIdsForUserId(userId);
362 Query q = manager.createQuery("select distinct f.owner from FileHeader f " +
363 "LEFT JOIN f.permissions p where f.owner.id != :userId and f.deleted=false " +
364 "and (p.user.id=:userId " + (groupIds.isEmpty() ? "" : "or p.group.id in (:groupIds)") + ")").
365 setParameter("userId", userId);
366 if (!groupIds.isEmpty())
367 q.setParameter("groupIds", groupIds);
368 return q.getResultList();
372 public List<FileHeader> getSharedFilesNotInSharedFolders(Long userId) throws ObjectNotFoundException {
374 throw new ObjectNotFoundException("No user specified");
375 User user = getEntityById(User.class, userId);
376 List<FileHeader> tempList = manager.createQuery("select distinct f from FileHeader f " +
377 "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
378 "and (f.readForAll=true or p.group.id != null or p.user.id != f.owner.id)" +
379 " and f.folder.id not in (select distinct fo.id from Folder fo LEFT JOIN " +
380 "fo.permissions po where fo.owner.id=:userId and fo.deleted=false and " +
381 "(po.group.id != null or po.user.id != fo.owner.id or fo.readForAll = true))").
382 setParameter("userId", userId).getResultList();
383 List<FileHeader> retv = new ArrayList<FileHeader>();
384 for (FileHeader f: tempList)
385 if (f.hasReadPermission(user)) retv.add(f);
391 public List<FileHeader> getSharedFiles(Long userId) throws ObjectNotFoundException {
393 throw new ObjectNotFoundException("No user specified");
394 User user = getEntityById(User.class, userId);
395 List<FileHeader> tempList = manager.createQuery("select distinct f from FileHeader f " +
396 "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
397 "and (p.group.id != null or p.user.id != f.owner.id)").
398 setParameter("userId", userId).getResultList();
399 List<FileHeader> retv = new ArrayList<FileHeader>();
400 for (FileHeader f: tempList)
401 if (f.hasReadPermission(user)) retv.add(f);
407 public List<Folder> getSharedFolders(Long userId) {
408 List<Folder> folders = manager.createQuery("select distinct f from Folder f " +
409 "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
410 "and (p.group.id != null or p.user.id != f.owner.id)").
411 setParameter("userId", userId).getResultList();
416 public List<FileHeader> getSharedFiles(Long userId, Long callingUserId) throws ObjectNotFoundException {
418 throw new ObjectNotFoundException("No user specified");
419 User user = getEntityById(User.class, userId);
420 List<FileHeader> tempList = manager.createQuery("select distinct f from FileHeader f " +
421 "LEFT JOIN f.permissions p where f.owner.id=:userId and f.deleted=false " +
422 "and p.read=true and (p.user.id=:cuserId or p.group.id in " +
423 "(select distinct gg.id from Group gg join gg.members memb " +
424 "where memb.id=:cuserId)) and f.folder.id not in (select distinct fo.id " +
425 "from Folder fo LEFT JOIN fo.permissions po where fo.owner.id = :userId " +
426 "and fo.deleted=false and po.read=true and (po.user.id=:cuserId " +
427 "or po.group.id in (select distinct ggo.id from Group ggo " +
428 "join ggo.members membo where membo.id=:cuserId)))").
429 setParameter("userId", userId).setParameter("cuserId", callingUserId).getResultList();
430 List<FileHeader> retv = new ArrayList<FileHeader>();
431 for (FileHeader f: tempList)
432 if (f.hasReadPermission(user)) retv.add(f);
438 public List<Folder> getSharedRootFolders(Long userId, Long callingUserId) {
439 List<Folder> folders = manager.createQuery("select distinct f from Folder f " +
440 "LEFT JOIN f.permissions p where f.owner.id = :userId and f.deleted=false " +
441 "and p.read=true and (p.user.id=:cuserId or p.group.id in " +
442 "(select distinct gg.id from Group gg join gg.members memb " +
443 "where memb.id=:cuserId))) ").
444 setParameter("userId", userId).
445 setParameter("cuserId", callingUserId).
447 List<Folder> result = new ArrayList<Folder>();
448 for(Folder f : folders)
449 if(!folders.contains(f.getParent()))
456 public List<FileHeader> searchFiles(Long userId, String query) {
457 return manager.createQuery("select f from FileHeader f where f.owner.id=:userId and f.name like :query").
458 setParameter("query", "%"+query+"%").setParameter("userId",userId).getResultList();
462 public Nonce getNonce(String nonce, Long userId) throws ObjectNotFoundException {
463 List<Nonce> results = manager.createQuery("select n from Nonce n where n.userId=:userId and n.encodedNonce=:nonce").
464 setParameter("userId", userId).setParameter("nonce", nonce).getResultList();
465 if (results.isEmpty())
466 throw new ObjectNotFoundException("No nonce found");
467 return results.get(0);
471 public Long getFileCount(Long userId) {
472 Long singleResult = (Long) manager.createQuery("select count(f) from FileHeader f where f.owner.id=:ownerId")
473 .setParameter("ownerId", userId)
479 public Long getFileSize(Long userId) {
480 Long singleResult = (Long) manager.createQuery("select sum(f.fileSize) from FileBody f where f.header.owner.id=:ownerId")
481 .setParameter("ownerId", userId)
483 if(singleResult == null)
484 singleResult = new Long(0L);
490 public List<Long> getAllFileIds() {
491 List<Long> ids = manager.createQuery("select f.id from FileHeader f").getResultList();
496 public FileUploadStatus getFileUploadStatus(Long userId, String fileName) {
497 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();
504 public FileBody getFileVersion(Long fileId, int version) throws ObjectNotFoundException {
506 return (FileBody) manager.createQuery("select f from FileBody f " +
507 "where f.header.id=:fileId and f.version=:version")
508 .setParameter("fileId", fileId).setParameter("version", version)
510 } catch (NoResultException e) {
511 throw new ObjectNotFoundException("No version " + version + " found for file #" + fileId);
516 public void updateAccounting(User user, Date date, long bandwidthDiff) {
517 AccountingInfo ai = null;
519 ai = (AccountingInfo) manager.createQuery("select ai from AccountingInfo ai " +
520 "where ai.user=:user and ai.dateFrom<=:date and ai.dateTo>:date")
521 .setParameter("user", user)
522 .setParameter("date", date)
525 catch (NoResultException e) {
530 // The right entry does not exist; must be created.
531 // This is where we set the initial time period.
532 // We now start from the user's creation, we can change this to something else.
533 Calendar creationDate = new GregorianCalendar();
534 creationDate.setTime(user.getAuditInfo().getCreationDate());
538 long timeInMillis = date.getTime();
540 dateFrom = (Calendar) creationDate.clone();
541 dateFrom.add(BANDWIDTH_TIME_PERIOD_FIELD, offset);
542 dateTo = (Calendar) dateFrom.clone();
543 dateTo.add(BANDWIDTH_TIME_PERIOD_FIELD, 1);
544 offset += BANDWIDTH_TIME_PERIOD_AMOUNT;
546 while (!(dateFrom.getTimeInMillis()<=timeInMillis && dateTo.getTimeInMillis()>timeInMillis));
548 ai = new AccountingInfo(user, dateFrom.getTime(), dateTo.getTime());
553 ai.updateBandwidth(bandwidthDiff);
557 public List<UserClass> getUserClasses() {
558 // Ordering by quota is important here.
559 List<UserClass> ids = manager.createQuery("select uc from UserClass uc order by uc.quota").getResultList();
564 public List<User> getUsersByUserNameOrEmailLike(String query) {
565 return manager.createQuery("select u from User u where " +
566 " upper(u.username) like :query or upper(u.email) like :query order by u.username").
567 setParameter("query", query.toUpperCase()+"%").getResultList();
571 public Invitation findInvite(String code) {
574 List<Invitation> results = manager.createQuery("select i from Invitation i where i.code=:code").
575 setParameter("code", code).getResultList();
576 if (results.isEmpty()) return null;
577 return results.get(0);
581 public UserClass findCouponUserClass() {
582 List<UserClass> results = manager.createQuery("select uc from UserClass uc where uc.name=:name").
583 setParameter("name", getConfiguration().getString("couponQuota")).getResultList();
584 if (results.isEmpty()) {
585 // Create the coupon user class on first use.
586 UserClass couponClass = new UserClass();
587 couponClass.setName("coupon");
588 Long couponQuota = getConfiguration().getLong("couponQuota", new Long(52428800L));
589 couponClass.setQuota(couponQuota);
592 results.add(couponClass);
594 return results.get(0);
598 public Long getFileCount(UserClass userClass) {
601 result=(Long) manager.createQuery("select count(f) from FileHeader f").getSingleResult();
602 else result= (Long) manager.createQuery("select count(f) from FileHeader f where f.owner.userClass.id=:id").setParameter("id", userClass.getId()).getSingleResult();
609 public Long getFileSize(UserClass userClass) {
612 result=(Long) manager.createQuery("select sum(f.currentBody.fileSize) from FileHeader f").getSingleResult();
613 else result=(Long) manager.createQuery("select sum(f.currentBody.fileSize) from FileHeader f where f.owner.userClass.id=:id").setParameter("id", userClass.getId()).getSingleResult();
620 public Long getUserCount(UserClass userClass) {
623 result = (Long) manager.createQuery("select count(u) from User u").getSingleResult();
624 else result = (Long) manager.createQuery("select count(u) from User u where u.userClass.id=:id").setParameter("id", userClass.getId()).getSingleResult();
631 public Long getCountUsersByLastLogin(Date lastLoginDate) {
632 return (Long) manager.createQuery("select count(u) from User u where " +
633 " u.lastLogin >= :ldate ").setParameter("ldate", lastLoginDate).getSingleResult();
637 public List<User> getUsersByLastLogin(Date lastLoginDate) {
638 return manager.createQuery("select u from User u where " +
639 " u.lastLogin >= :ldate order by u.lastLogin desc").
640 setParameter("ldate", lastLoginDate).getResultList();
644 public List<User> getUsersByLastLogin(Date lastLoginDate, int firstResult, int maxResult) {
645 return manager.createQuery("select u from User u where " +
646 " u.lastLogin >= :ldate order by u.lastLogin desc").
647 setParameter("ldate", lastLoginDate).setFirstResult(firstResult).setMaxResults(maxResult).getResultList();
651 public List<User> getInactiveUsers() {
652 return manager.createQuery("select u from User u where u.active=:active").setParameter("active", false).getResultList();
656 public List<FileHeader> searchFileByFilename(String filename) {
657 return manager.createQuery("select f from FileHeader f where f.name=:name").setParameter("name", filename).getResultList();
661 public Long getBandwithUsed(UserClass userClass, Date date) {
663 if (userClass == null)
664 result = (Long) manager.createQuery("select sum(ai.bandwidthUsed)" +
665 " from AccountingInfo ai where ai.dateFrom<=:date and " +
667 setParameter("date", date).
670 result = (Long) manager.createQuery("select sum(ai.bandwidthUsed)" +
671 " from AccountingInfo ai where ai.user.userClass.id=:id " +
672 "and ai.dateFrom<=:date and ai.dateTo>:date").
673 setParameter("date", date).
674 setParameter("id", userClass.getId()).
682 public List<AccountingInfo> getAccountingInfo(User user) {
683 List<AccountingInfo> ai = new ArrayList<AccountingInfo>();
685 ai = manager.createQuery("select ai from AccountingInfo ai " +
686 "where ai.user=:user")
687 .setParameter("user", user)
690 catch (NoResultException e) {}
695 public AccountingInfo getAccountingInfo(User user, Date date) {
696 AccountingInfo ai = null;
698 ai = (AccountingInfo) manager.createQuery("select ai from AccountingInfo ai " +
699 "where ai.user=:user and ai.dateFrom<=:date and ai.dateTo>:date")
700 .setParameter("user", user)
701 .setParameter("date", date)
704 catch (NoResultException e) {
705 // If not found, that means that there is no accounting info noted
706 // for given time. So return a 0 as an answer.
707 ai = new AccountingInfo(user, date, date);
713 public List<FileHeader> getFilesPermittedForGroup(Long userId, Long groupId) {
714 return manager.createQuery("select distinct f from FileHeader f LEFT JOIN f.permissions p " +
715 "where f.owner.id=:userId and f.deleted = false and p.group.id=:groupId ").
716 setParameter("userId", userId).setParameter("groupId", groupId).getResultList();
720 public List<Folder> getSharingFoldersForUser(Long userId) {
721 return manager.createQuery("select distinct f from Folder f " +
722 "LEFT JOIN f.permissions p where " +
723 " (p.user.id=:userId or p.group.id in (select distinct gg.id " +
724 "from Group gg join gg.members memb where memb.id=:userId))) ").
725 setParameter("userId", userId).getResultList();
729 public List<FileHeader> getSharingFilesForUser(Long userId) {
730 List<FileHeader> users = manager.createQuery("select distinct f from FileHeader f " +
731 "LEFT JOIN f.permissions p where " +
732 " (p.user.id=:userId or p.group.id in (select distinct gg.id from Group gg " +
733 "join gg.members memb where memb.id=:userId)))").
734 setParameter("userId", userId).getResultList();
739 public FileHeader getFileForIndexing(Long id) throws ObjectNotFoundException {
740 FileHeader h = getEntityById(FileHeader.class, id);
741 h.getFileTags().size();
742 h.getPermissions().size();
747 public List<Group> getGroupsContainingUser(Long userId){
748 List<Group> groups = manager.createQuery("select distinct gg " +
749 "from Group gg join gg.members memb where memb.id=:userId)").setParameter("userId", userId).getResultList();
754 public List<FileUploadStatus> getUploadStatus(Long userId){
755 List<FileUploadStatus> res = manager.createQuery("select f from FileUploadStatus f where f.owner.id=:userId").setParameter("userId", userId).getResultList();
759 public int deletePermissionsNotCorrespondingToFilesAndFolders(Long userId){
760 return manager.createNativeQuery("delete from permission where user_id=:userId and id not in(select permissions_id from fileheader_permission) and id not in(select permissions_id from folder_permission)").setParameter("userId", userId).executeUpdate();
763 public List<UserLogin> getLoginsForUser (Long userId){
764 List<UserLogin> res = manager
765 .createQuery("select ul from UserLogin ul where ul.user.id=:userId " +
766 " order by ul.loginDate desc")
767 .setParameter("userId", userId)