diff --git a/src/main/java/org/olat/core/commons/services/scheduler/_spring/schedulerContext.xml b/src/main/java/org/olat/core/commons/services/scheduler/_spring/schedulerContext.xml index 907b85c71e4a05f4c84ada968ce87427b87803ab..aefc59b1293951d99e23ac1023691ce660a45bc8 100644 --- a/src/main/java/org/olat/core/commons/services/scheduler/_spring/schedulerContext.xml +++ b/src/main/java/org/olat/core/commons/services/scheduler/_spring/schedulerContext.xml @@ -37,7 +37,6 @@ How to add a new job: <ref bean="sendNotificationsEmailTrigger" /> <ref bean="updateStatisticsTrigger"/> <ref bean="searchIndexingTrigger"/> - <ref bean="invitationCleanupTrigger" /> <ref bean="restTokenTrigger" /> <ref bean="taskExecutorTrigger" /> <ref bean="procSamplerTrigger"/> diff --git a/src/main/java/org/olat/modules/_spring/modulesContext.xml b/src/main/java/org/olat/modules/_spring/modulesContext.xml index 7d55dd77fc2b86d1ca97a9f076b817c75b8ffbdc..5ad479379006dcf44568aa072505a53e51e9c049 100644 --- a/src/main/java/org/olat/modules/_spring/modulesContext.xml +++ b/src/main/java/org/olat/modules/_spring/modulesContext.xml @@ -197,37 +197,6 @@ </property> </bean> - <bean id="invitationCleanupTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> - <property name="jobDetail" ref="invitationCleanupJob.${cluster.singleton.services}" /> - <!-- adjust cron style syntax for your notification needs - "0 10 0 * *" e.g. 10 minutes after midnight - - A "Cron-Expression" is a string comprised of 6 or 7 fields separated by white space. The 6 mandatory and 1 optional fields are as follows: - Field Name Allowed Values Allowed Special Characters - Seconds 0-59 , - * / - Minutes 0-59 , - * / - Hours 0-23 , - * / - Day-of-month 1-31 , - * ? / L W C - Month 1-12 or JAN-DEC , - * / - Day-of-Week 1-7 or SUN-SAT , - * ? / L C # - Year (Optional) empty, 1970-2099 , - * / - - As of OLAT 6.3 it's best to let the cronjob run every two hours since users can now choose how often - they will get notified. The shortest interval is set to two hours. - --> - <property name="cronExpression" value="0 2 */12 * * ?" /> - <property name="startDelay" value="150000" /> - </bean> - - <bean id="invitationCleanupJob.enabled" class="org.springframework.scheduling.quartz.JobDetailFactoryBean" lazy-init="true"> - <property name="jobClass" value="org.olat.modules.portfolio.manager.InvitationCleanupJob" /> - </bean> - <!-- dummy bean --> - <bean id="invitationCleanupJob.disabled" class="org.springframework.scheduling.quartz.JobDetailFactoryBean" lazy-init="true"> - <property name="jobClass" value="org.olat.core.commons.services.scheduler.DummyJob" /> - </bean> - - <!-- vitero admin. panel --> <bean class="org.olat.core.extensions.action.GenericActionExtension" init-method="initExtensionPoints"> <property name="order" value="8228" /> 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 faa4cc5c5b256667b6d47d1a52b666840f5e1266..37a4adf45ef1f3a65bf3732de8969e37dc79c903 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/BinderDAO.java +++ b/src/main/java/org/olat/modules/portfolio/manager/BinderDAO.java @@ -84,6 +84,8 @@ public class BinderDAO { @Autowired private GroupDAO groupDao; @Autowired + private InvitationDAO invitationDao; + @Autowired private AssignmentDAO assignmentDao; @Autowired private PageUserInfosDAO pageUserInfosDao; @@ -459,8 +461,8 @@ public class BinderDAO { binder.getSections().clear(); - Group baseGroup = binder.getBaseGroup(); + invitationDao.deleteInvitation(baseGroup); rows += groupDao.removeMemberships(baseGroup); dbInstance.getCurrentEntityManager().remove(binder); dbInstance.getCurrentEntityManager().remove(baseGroup); @@ -495,22 +497,20 @@ public class BinderDAO { public int detachBinderFromRepositoryEntry(RepositoryEntry entry) { //remove reference to the course and the course node String sb = "update pfbinder binder set binder.entry=null,binder.subIdent=null where binder.entry.key=:entryKey"; - int rows = dbInstance.getCurrentEntityManager() + return dbInstance.getCurrentEntityManager() .createQuery(sb) .setParameter("entryKey", entry.getKey()) .executeUpdate(); - return rows; } public int detachBinderFromRepositoryEntry(RepositoryEntry entry, PortfolioCourseNode node) { //remove reference to the course and the course node String sb = "update pfbinder binder set binder.entry=null,binder.subIdent=null where binder.entry.key=:entryKey and binder.subIdent=:nodeIdent"; - int rows = dbInstance.getCurrentEntityManager() + return dbInstance.getCurrentEntityManager() .createQuery(sb) .setParameter("entryKey", entry.getKey()) .setParameter("nodeIdent", node.getIdent()) .executeUpdate(); - return rows; } /** diff --git a/src/main/java/org/olat/modules/portfolio/manager/InvitationCleanupJob.java b/src/main/java/org/olat/modules/portfolio/manager/InvitationCleanupJob.java deleted file mode 100644 index ed3b1cfb6de869edb12e576650ad2a4b54cea2a0..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/modules/portfolio/manager/InvitationCleanupJob.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * <a href="http://www.openolat.org"> - * OpenOLAT - Online Learning and Training</a><br> - * <p> - * Licensed under the Apache License, Version 2.0 (the "License"); <br> - * you may not use this file except in compliance with the License.<br> - * You may obtain a copy of the License at the - * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> - * <p> - * Unless required by applicable law or agreed to in writing,<br> - * software distributed under the License is distributed on an "AS IS" BASIS, <br> - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> - * See the License for the specific language governing permissions and <br> - * limitations under the License. - * <p> - * Initial code contributed and copyrighted by<br> - * frentix GmbH, http://www.frentix.com - * <p> - */ -package org.olat.modules.portfolio.manager; - -import org.apache.logging.log4j.Logger; -import org.olat.core.CoreSpringFactory; -import org.olat.core.commons.services.scheduler.JobWithDB; -import org.olat.core.logging.Tracing; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.JobExecutionContext; - -/** - * Description:<br> - * A job to remove invitation without policies. - * - * <P> - * Initial Date: 11 nov. 2010 <br> - * @author srosse - */ -@DisallowConcurrentExecution -public class InvitationCleanupJob extends JobWithDB { - - private static final Logger log = Tracing.createLoggerFor(InvitationCleanupJob.class); - - @Override - public void executeWithDB(JobExecutionContext context) { - try { - log.info("Starting invitation clean up job"); - InvitationDAO invitationDao = CoreSpringFactory.getImpl(InvitationDAO.class); - invitationDao.cleanUpInvitations(); - } catch (Exception e) { - // ups, something went completely wrong! We log this but continue next time - log.error("Error while cleaning up invitation", e); - } - // db closed by JobWithDB class - } -} diff --git a/src/main/java/org/olat/modules/portfolio/manager/InvitationDAO.java b/src/main/java/org/olat/modules/portfolio/manager/InvitationDAO.java index b7a3df765e71e29fdfbe29bd0a4332e7decdf4bd..cc716f4c053f87f36ae9bbfe080398599f850ad8 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/InvitationDAO.java +++ b/src/main/java/org/olat/modules/portfolio/manager/InvitationDAO.java @@ -19,7 +19,6 @@ */ package org.olat.modules.portfolio.manager; -import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Locale; @@ -35,13 +34,11 @@ import org.olat.basesecurity.Invitation; import org.olat.basesecurity.OrganisationRoles; import org.olat.basesecurity.OrganisationService; import org.olat.basesecurity.manager.GroupDAO; -import org.olat.basesecurity.manager.OrganisationDAO; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; import org.olat.core.id.User; import org.olat.core.id.UserConstants; import org.olat.modules.portfolio.model.InvitationImpl; -import org.olat.user.UserLifecycleManager; import org.olat.user.UserManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -69,11 +66,7 @@ public class InvitationDAO { @Autowired private BaseSecurity securityManager; @Autowired - private OrganisationDAO organisationDao; - @Autowired private OrganisationService organisationService; - @Autowired - private UserLifecycleManager userLifecycleManager; public Invitation createInvitation() { InvitationImpl invitation = new InvitationImpl(); @@ -164,10 +157,10 @@ public class InvitationDAO { StringBuilder sb = new StringBuilder(); sb.append("select invitation.key from binvitation as invitation") .append(" inner join invitation.baseGroup as baseGroup") - .append(" where invitation.token=:token ") - .append(" and exists(select binder from pfbinder as binder") - .append(" where binder.baseGroup.key=baseGroup.key") - .append(" )"); + .append(" where invitation.token=:token") + .append(" and exists(select binder from pfbinder as binder") + .append(" where binder.baseGroup.key=baseGroup.key") + .append(" )"); TypedQuery<Long> query = dbInstance.getCurrentEntityManager() .createQuery(sb.toString(), Long.class) @@ -177,7 +170,7 @@ public class InvitationDAO { .setFirstResult(0) .setMaxResults(1) .getResultList(); - return keys == null || keys.isEmpty() || keys.get(0) == null ? false : keys.get(0).longValue() > 0; + return keys != null && !keys.isEmpty() && keys.get(0) != null && keys.get(0).longValue() > 0; } /** @@ -198,25 +191,6 @@ public class InvitationDAO { return invitations.isEmpty() ? null : invitations.get(0); } - /** - * Find an invitation by its security group - * @param secGroup - * @return The invitation or null if not found - */ - public Invitation findInvitation(Group group) { - StringBuilder sb = new StringBuilder(); - sb.append("select invitation from binvitation as invitation ") - .append(" inner join fetch invitation.baseGroup bGroup") - .append(" where bGroup=:group"); - - List<Invitation> invitations = dbInstance.getCurrentEntityManager() - .createQuery(sb.toString(), Invitation.class) - .setParameter("group", group) - .getResultList(); - if(invitations.isEmpty()) return null; - return invitations.get(0); - } - /** * * Warning! The E-mail is used in this case as a foreign key to match @@ -295,7 +269,7 @@ public class InvitationDAO { .createQuery(sb.toString(), Number.class) .setParameter("identityKey", identity.getKey()) .getSingleResult(); - return invitations == null ? false : invitations.intValue() > 0; + return invitations != null && invitations.intValue() > 0; } /** @@ -310,46 +284,13 @@ public class InvitationDAO { dbInstance.getCurrentEntityManager().remove(refInvitation); } - /** - * Clean up old invitation and set to deleted temporary users - */ - public void cleanUpInvitations() { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - cal.add(Calendar.HOUR, -6); - Date dateLimit = cal.getTime(); - - StringBuilder sb = new StringBuilder(512); - sb.append("select invitation from ").append(InvitationImpl.class.getName()).append(" as invitation ") - .append(" inner join invitation.baseGroup baseGroup ") - .append(" where invitation.creationDate<:dateLimit"); - - List<Invitation> oldInvitations = dbInstance.getCurrentEntityManager() - .createQuery(sb.toString(), Invitation.class) - .setParameter("dateLimit", dateLimit) - .getResultList(); + public int deleteInvitation(Group group) { + if(group == null || group.getKey() == null) return 0; - if(oldInvitations.isEmpty()) { - return; - } - - for(Invitation invitation:oldInvitations) { - List<Identity> identities = groupDao.getMembers(invitation.getBaseGroup(), GroupRoles.invitee.name()); - //normally only one identity - for(Identity identity:identities) { - if(identity.getStatus().equals(Identity.STATUS_DELETED)) { - //already deleted - } else if(organisationDao.hasAnyRole(identity, OrganisationRoles.invitee.name())) { - //out of scope - } else { - //delete user - userLifecycleManager.deleteIdentity(identity, null); - } - } - Invitation invitationRef = dbInstance.getCurrentEntityManager() - .getReference(InvitationImpl.class, invitation.getKey()); - dbInstance.getCurrentEntityManager().remove(invitationRef); - dbInstance.commit(); - } + String delete = "delete from binvitation as invitation where invitation.baseGroup.key=:groupKey"; + return dbInstance.getCurrentEntityManager() + .createQuery(delete) + .setParameter("groupKey", group.getKey()) + .executeUpdate(); } } diff --git a/src/main/java/org/olat/modules/portfolio/ui/BinderListController.java b/src/main/java/org/olat/modules/portfolio/ui/BinderListController.java index 51bcc10c34670101b8e1cb7de8b382b5e10e68bc..96020a285a3b7c947ad82d726b4ceb657aaf74cd 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/BinderListController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/BinderListController.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; @@ -133,6 +134,8 @@ public class BinderListController extends FormBasicController private ConfirmMoveBinderToTrashController moveBinderToTrashCtrl; private DialogBoxController confirmRestoreBinderCtrl; + @Autowired + private DB dbInstance; @Autowired private PortfolioV2Module portfolioModule; @Autowired @@ -736,7 +739,8 @@ public class BinderListController extends FormBasicController private void doMoveBinderToTrash(BinderRow row) { Binder binder = portfolioService.getBinderByKey(row.getKey()); binder.setBinderStatus(BinderStatus.deleted); - binder = portfolioService.updateBinder(binder); + portfolioService.updateBinder(binder); + dbInstance.commit(); showInfo("delete.binder.success"); } @@ -756,6 +760,7 @@ public class BinderListController extends FormBasicController private void doDeleteBinder(BinderRef binder) { portfolioService.deleteBinder(binder); + dbInstance.commit(); showInfo("delete.binder.success"); } @@ -769,7 +774,7 @@ public class BinderListController extends FormBasicController private void doRestore(BinderRef row) { Binder binder = portfolioService.getBinderByKey(row.getKey()); binder.setBinderStatus(BinderStatus.open); - binder = portfolioService.updateBinder(binder); + portfolioService.updateBinder(binder); showInfo("restore.binder.success"); } diff --git a/src/main/java/org/olat/modules/portfolio/ui/BinderMetadataEditController.java b/src/main/java/org/olat/modules/portfolio/ui/BinderMetadataEditController.java index b83aa4cf10b441fe3604e0da6514aeadfc8348bd..aee71ac92ed76d38313ea1caadd5e7087113e4ea 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/BinderMetadataEditController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/BinderMetadataEditController.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.olat.core.commons.persistence.DB; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -79,6 +80,8 @@ public class BinderMetadataEditController extends FormBasicController { private Map<String,String> categories = new HashMap<>(); private Map<String,Category> categoriesMap = new HashMap<>(); + @Autowired + private DB dbInstance; @Autowired private UserManager userManager; @Autowired @@ -229,6 +232,7 @@ public class BinderMetadataEditController extends FormBasicController { List<String> updatedCategories = categoriesEl.getValueList(); portfolioService.updateCategories(binder, updatedCategories); + dbInstance.commit(); fireEvent(ureq, Event.DONE_EVENT); } diff --git a/src/main/java/org/olat/modules/portfolio/ui/DeletedBinderController.java b/src/main/java/org/olat/modules/portfolio/ui/DeletedBinderController.java index 4840ab4fe5096a6a1c86b6d0ba83b321d6eba772..181963144030cdf043caa737aace66b13a47d8a8 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/DeletedBinderController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/DeletedBinderController.java @@ -22,6 +22,7 @@ package org.olat.modules.portfolio.ui; import java.util.ArrayList; import java.util.List; +import org.olat.core.commons.persistence.DB; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -52,6 +53,7 @@ import org.olat.modules.portfolio.model.BinderStatistics; import org.olat.modules.portfolio.ui.event.DeleteBinderEvent; import org.olat.modules.portfolio.ui.event.RestoreBinderEvent; import org.olat.modules.portfolio.ui.model.BinderRow; +import org.springframework.beans.factory.annotation.Autowired; /** * @@ -66,6 +68,9 @@ public class DeletedBinderController extends BinderListController { private DialogBoxController confirmRestoreBinderCtrl; private ConfirmDeleteBinderController deleteBinderCtrl; + @Autowired + private DB dbInstance; + public DeletedBinderController(UserRequest ureq, WindowControl wControl, TooledStackedPanel stackPanel) { super(ureq, wControl, stackPanel); } @@ -225,7 +230,8 @@ public class DeletedBinderController extends BinderListController { private void doRestore(BinderRow row) { Binder binder = portfolioService.getBinderByKey(row.getKey()); binder.setBinderStatus(BinderStatus.open); - binder = portfolioService.updateBinder(binder); + portfolioService.updateBinder(binder); + dbInstance.commit(); showInfo("restore.binder.success"); } } \ No newline at end of file diff --git a/src/main/java/org/olat/modules/portfolio/ui/SectionEditController.java b/src/main/java/org/olat/modules/portfolio/ui/SectionEditController.java index 49e460f3a7ae142179f1ad4d6314278bf0b24bda..cc08533beedb71584a6ab8bc385db5be96195768 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/SectionEditController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/SectionEditController.java @@ -31,6 +31,7 @@ import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; +import org.olat.core.util.StringHelper; import org.olat.modules.portfolio.BinderRef; import org.olat.modules.portfolio.BinderSecurityCallback; import org.olat.modules.portfolio.PortfolioService; @@ -95,6 +96,9 @@ public class SectionEditController extends FormBasicController { titleEl = uifactory.addTextElement("title", "title", 255, title, formLayout); titleEl.setElementCssClass("o_sel_pf_edit_section_title"); titleEl.setMandatory(true); + if(!StringHelper.containsNonWhitespace(title)) { + titleEl.setFocus(true); + } String description = section == null ? null : section.getDescription(); descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("summary", "page.summary", description, 8, 60, formLayout, getWindowControl()); diff --git a/src/main/java/org/olat/modules/portfolio/ui/TableOfContentController.java b/src/main/java/org/olat/modules/portfolio/ui/TableOfContentController.java index debe917bf60f238a486f8775917b8d4c25723e77..daf0f4dbfc1b26340f11255dd1cd7c13ff92f8d3 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/TableOfContentController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/TableOfContentController.java @@ -27,6 +27,7 @@ import java.util.Map; import org.olat.NewControllerFactory; import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; import org.olat.core.commons.fullWebApp.popup.BaseFullWebappPopupLayoutFactory; +import org.olat.core.commons.persistence.DB; import org.olat.core.commons.services.commentAndRating.CommentAndRatingDefaultSecurityCallback; import org.olat.core.commons.services.commentAndRating.CommentAndRatingSecurityCallback; import org.olat.core.commons.services.commentAndRating.ReadOnlyCommentsSecurityCallback; @@ -151,6 +152,8 @@ public class TableOfContentController extends BasicController implements TooledC private final BinderConfiguration config; private final BinderSecurityCallback secCallback; + @Autowired + private DB dbInstance; @Autowired private PdfModule pdfModule; @Autowired @@ -955,8 +958,10 @@ public class TableOfContentController extends BasicController implements TooledC } private void doMoveBinderToTrash() { + binder = portfolioService.getBinderByKey(binder.getKey()); binder.setBinderStatus(BinderStatus.deleted); binder = portfolioService.updateBinder(binder); + dbInstance.commit(); showInfo("delete.binder.success"); } @@ -967,8 +972,10 @@ public class TableOfContentController extends BasicController implements TooledC } private void doRestore() { + binder = portfolioService.getBinderByKey(binder.getKey()); binder.setBinderStatus(BinderStatus.open); binder = portfolioService.updateBinder(binder); + dbInstance.commit(); showInfo("restore.binder.success"); } diff --git a/src/test/java/org/olat/modules/portfolio/manager/InvitationDAOTest.java b/src/test/java/org/olat/modules/portfolio/manager/InvitationDAOTest.java index af3e5d241080675b0d676fe008352637eaa99f89..1a6c556e06a46c6c3a6531d9b5077a8bdf888801 100644 --- a/src/test/java/org/olat/modules/portfolio/manager/InvitationDAOTest.java +++ b/src/test/java/org/olat/modules/portfolio/manager/InvitationDAOTest.java @@ -30,6 +30,7 @@ import org.olat.basesecurity.Invitation; import org.olat.basesecurity.manager.GroupDAO; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; +import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; import org.springframework.beans.factory.annotation.Autowired; @@ -63,21 +64,6 @@ public class InvitationDAOTest extends OlatTestCase { Assert.assertNotNull(invitation.getToken()); } - @Test - public void findInvitation_group() { - Invitation invitation = invitationDao.createAndPersistInvitation(); - Group baseGroup = invitation.getBaseGroup(); - Assert.assertNotNull(invitation); - dbInstance.commitAndCloseSession(); - - Invitation reloadedInvitation = invitationDao.findInvitation(baseGroup); - Assert.assertNotNull(reloadedInvitation); - Assert.assertNotNull(reloadedInvitation.getKey()); - Assert.assertEquals(baseGroup, reloadedInvitation.getBaseGroup()); - Assert.assertEquals(invitation, reloadedInvitation); - Assert.assertEquals(invitation.getToken(), reloadedInvitation.getToken()); - } - @Test public void findInvitation_token() { Invitation invitation = invitationDao.createAndPersistInvitation(); @@ -93,12 +79,31 @@ public class InvitationDAOTest extends OlatTestCase { } @Test - public void hasInvitationPolicies_testHQL() { + public void hasInvitationTestHQL() { String token = UUID.randomUUID().toString(); boolean hasInvitation = invitationDao.hasInvitations(token); Assert.assertFalse(hasInvitation); } + @Test + public void isInvitee() { + Invitation invitation = invitationDao.createInvitation(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + invitation.setFirstName("Fiona"); + invitation.setLastName("Laurence".concat(uuid)); + invitation.setMail(uuid.concat("@frentix.com")); + + Group group = groupDao.createGroup(); + Identity id2 = invitationDao.loadOrCreateIdentityAndPersistInvitation(invitation, group, Locale.ENGLISH); + Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("Invitee-2"); + dbInstance.commitAndCloseSession(); + + boolean invitee = invitationDao.isInvitee(id2); + Assert.assertTrue(invitee); + boolean notInvitee = invitationDao.isInvitee(id1); + Assert.assertFalse(notInvitee); + } + @Test public void createAndUpdateInvitation() { Invitation invitation = invitationDao.createAndPersistInvitation(); @@ -174,12 +179,16 @@ public class InvitationDAOTest extends OlatTestCase { Assert.assertTrue(numOfInvitations > 0l); } - /** - * Only check if the query is valid. - */ @Test - public void cleanUpInvitations() { - invitationDao.cleanUpInvitations(); + public void deleteInvitationByGroup() { + Invitation invitation = invitationDao.createAndPersistInvitation(); + dbInstance.commit(); + Assert.assertNotNull(invitation); + + invitationDao.deleteInvitation(invitation.getBaseGroup()); + dbInstance.commit(); + + Invitation deletedInvitation = invitationDao.findInvitation(invitation.getToken()); + Assert.assertNull(deletedInvitation); } - }