Skip to content
Snippets Groups Projects
Commit 5825c737 authored by srosse's avatar srosse
Browse files

OO-4578: catch duplicate user efficiency statement persistence

parent ec208346
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,10 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.persistence.PersistenceException;
import org.apache.logging.log4j.Logger;
import org.hibernate.exception.ConstraintViolationException;
import org.olat.basesecurity.GroupRoles;
import org.olat.basesecurity.IdentityRef;
import org.olat.core.commons.persistence.DB;
......@@ -220,7 +223,7 @@ public class EfficiencyStatementManager implements UserDataDeletable, UserDataEx
efficiencyProperty.setShortTitle(courseEnv.getRunStructure().getRootNode().getShortTitle());
efficiencyProperty.setTitle(courseEnv.getRunStructure().getRootNode().getLongTitle());
fillEfficiencyStatement(efficiencyStatement, lastModifications, efficiencyProperty);
dbInstance.getCurrentEntityManager().persist(efficiencyProperty);
efficiencyProperty = persistOrLoad(efficiencyProperty, repoEntry, assessedIdentity);
if (debug) {
log.debug("creating new efficiency statement property::{} for id::{} repoEntry:: {}",
efficiencyProperty.getKey(), assessedIdentity.getKey() , repoEntry.getKey());
......@@ -254,6 +257,23 @@ public class EfficiencyStatementManager implements UserDataDeletable, UserDataEx
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, courseOres);
}
private UserEfficiencyStatementImpl persistOrLoad(UserEfficiencyStatementImpl efficiencyProperty, RepositoryEntry entry, Identity identity) {
try {
dbInstance.commit();
dbInstance.getCurrentEntityManager().persist(efficiencyProperty);
dbInstance.commit();
} catch(PersistenceException e) {
if(e.getCause() instanceof ConstraintViolationException) {
log.warn("", e);
dbInstance.rollback();
efficiencyProperty = getUserEfficiencyStatementFull(entry, identity);
} else {
log.error("", e);
}
}
return efficiencyProperty;
}
public void fillEfficiencyStatement(EfficiencyStatement efficiencyStatement, AssessmentNodesLastModified lastModifications, UserEfficiencyStatementImpl efficiencyProperty) {
if(lastModifications != null) {
if(lastModifications.getLastUserModified() != null
......
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