From a499f47cf691f5b434ed9a1a59ec3595b89a1dd6 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Fri, 18 May 2018 16:20:16 +0200 Subject: [PATCH] OO-3479: make two methods to retrieve the owned binders --- .../modules/portfolio/manager/BinderDAO.java | 26 ++++++++++++++++++- .../manager/PortfolioServiceImpl.java | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/olat/modules/portfolio/manager/BinderDAO.java b/src/main/java/org/olat/modules/portfolio/manager/BinderDAO.java index f8dac00140a..45b3173fdfa 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/BinderDAO.java +++ b/src/main/java/org/olat/modules/portfolio/manager/BinderDAO.java @@ -344,7 +344,11 @@ public class BinderDAO { return dbInstance.getCurrentEntityManager().merge(binder); } - public List<Binder> getOwnedBinders(IdentityRef owner) { + /** + * @param owner The owner + * @return All the binder where the specified identity as the role owner + */ + public List<Binder> getAllBindersAsOwner(IdentityRef owner) { StringBuilder sb = new StringBuilder(); sb.append("select binder from pfbinder as binder") .append(" inner join fetch binder.baseGroup as baseGroup") @@ -359,6 +363,26 @@ public class BinderDAO { .getResultList(); } + /** + * + * @param owner The owner + * @return The binder where the specified identity has the role 'owner' and the binder is still open. + */ + public List<Binder> getOwnedBinders(IdentityRef owner) { + StringBuilder sb = new StringBuilder(); + sb.append("select binder from pfbinder as binder") + .append(" inner join fetch binder.baseGroup as baseGroup") + .append(" inner join baseGroup.members as membership") + .append(" where membership.identity.key=:identityKey and membership.role=:role") + .append(" and (binder.status is null or binder.status='").append(BinderStatus.open.name()).append("')"); + + return dbInstance.getCurrentEntityManager() + .createQuery(sb.toString(), Binder.class) + .setParameter("identityKey", owner.getKey()) + .setParameter("role", PortfolioRoles.owner.name()) + .getResultList(); + } + public List<Binder> getOwnedBinderFromCourseTemplate(IdentityRef owner) { StringBuilder sb = new StringBuilder(); sb.append("select binder from pfbinder as binder") diff --git a/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java b/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java index 27362495ef6..2915b6d7c3a 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java +++ b/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java @@ -288,7 +288,7 @@ public class PortfolioServiceImpl implements PortfolioService, DeletableGroupDat @Override public void deleteUserData(Identity identity, String newDeletedUserName, File archivePath) { - List<Binder> ownedBinders = binderDao.getOwnedBinders(identity); + List<Binder> ownedBinders = binderDao.getAllBindersAsOwner(identity); for(Binder ownedBinder:ownedBinders) { OLATResource resource = ((BinderImpl)ownedBinder).getOlatResource(); if(resource != null) { -- GitLab