Skip to content
Snippets Groups Projects
Commit 5bd943c1 authored by srosse's avatar srosse
Browse files

OO-4890: update ratings statistics must survive a missing resource

parent d3694f02
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ package org.olat.repository.manager;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.persistence.LockModeType;
......@@ -132,15 +133,16 @@ public class RepositoryEntryStatisticsDAO implements UserRatingsDelegate, UserCo
dbInstance.getCurrentEntityManager().detach(re.getStatistics());
}
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(256);
sb.append("select stats from ").append(RepositoryEntryStatistics.class.getName()).append(" as stats")
.append(" where stats.key in (select v.statistics.key from ").append(RepositoryEntry.class.getName()).append(" as v where v.key=:key)");
return dbInstance.getCurrentEntityManager()
List<RepositoryEntryStatistics> statistics = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), RepositoryEntryStatistics.class)
.setParameter("key", repositoryEntryRes.getResourceableId())
.setLockMode(LockModeType.PESSIMISTIC_WRITE)
.getSingleResult();
.getResultList();
return statistics == null || statistics.isEmpty() ? null : statistics.get(0);
}
@Override
......
......@@ -41,6 +41,7 @@ import org.olat.core.id.OLATResourceable;
import org.olat.core.id.Organisation;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing;
import org.olat.core.util.resource.OresHelper;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryEntryStatusEnum;
import org.olat.repository.RepositoryManager;
......@@ -133,6 +134,14 @@ public class RepositoryEntryStatisticsDAOTest extends OlatTestCase {
Assert.assertEquals(1, stats.getNumOfComments());
}
@Test
public void updateCommentsStatisticsOfGhostResource() {
OLATResourceable ores = OresHelper.createOLATResourceableInstance("LifeIsBeautiful", 42l);
boolean updated = reStatisticsDao.update(ores, "apath", 3);
Assert.assertFalse(updated);
dbInstance.commit();// ensure the session is viable
}
@Test
public void incrementLaunchCounter() {
Organisation defOrganisation = organisationService.getDefaultOrganisation();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment