use of org.olat.course.CorruptedCourseException in project openolat by klemens.
the class QTIEditorMainController method createReferenceesMsg.
/**
* helper method to create the message about qti resource stakeholders and
* from where the qti resource is referenced.
*
* @return
*/
private String createReferenceesMsg(UserRequest ureq) {
/*
* problems: A tries to reference this test, after test editor has been
* started
*/
changeEmail = new ContactMessage(ureq.getIdentity());
// the owners of this qtiPkg
RepositoryEntry myEntry = repositoryManager.lookupRepositoryEntry(qtiPackage.getRepresentingResourceable(), false);
// add qti resource owners as group
ContactList cl = new ContactList("qtiPkgOwners");
cl.addAllIdentites(repositoryService.getMembers(myEntry, GroupRoles.owner.name()));
changeEmail.addEmailTo(cl);
StringBuilder result = new StringBuilder();
result.append(translate("qti.restricted.leading"));
for (Iterator<Reference> iter = referencees.iterator(); iter.hasNext(); ) {
Reference element = iter.next();
if ("CourseModule".equals(element.getSource().getResourceableTypeName())) {
ICourse course = null;
try {
course = CourseFactory.loadCourse(element.getSource().getResourceableId());
if (course == null) {
continue;
}
} catch (CorruptedCourseException ex) {
logError("", ex);
continue;
}
CourseNode cn = course.getEditorTreeModel().getCourseNode(element.getUserdata());
if (cn == null) {
logError("Cannot find course element " + element.getUserdata() + " in course " + course, null);
continue;
}
String courseTitle = course.getCourseTitle();
StringBuilder stakeHolders = new StringBuilder();
// the course owners
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course, false);
if (entry != null) {
// OO-1300
List<Identity> stakeHoldersIds = repositoryService.getMembers(entry, GroupRoles.owner.name());
if (stakeHoldersIds != null && stakeHoldersIds.size() > 0) {
// add stakeholders as group
cl = new ContactList(courseTitle);
cl.addAllIdentites(stakeHoldersIds);
changeEmail.addEmailTo(cl);
for (Identity stakeHoldersId : stakeHoldersIds) {
if (stakeHolders.length() > 0)
stakeHolders.append(", ");
User user = stakeHoldersId.getUser();
stakeHolders.append(user.getProperty(UserConstants.FIRSTNAME, getLocale())).append(" ").append(user.getProperty(UserConstants.LASTNAME, getLocale()));
}
}
}
String courseNodeTitle = cn.getShortTitle();
result.append(translate("qti.restricted.course", StringHelper.escapeHtml(courseTitle)));
result.append(translate("qti.restricted.node", StringHelper.escapeHtml(courseNodeTitle)));
result.append(translate("qti.restricted.owners", stakeHolders.toString()));
}
}
return result.toString();
}
use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.
the class CourseHandler method readyToDelete.
@Override
public boolean readyToDelete(RepositoryEntry entry, Identity identity, Roles roles, Locale locale, ErrorList errors) {
ReferenceManager refM = CoreSpringFactory.getImpl(ReferenceManager.class);
String referencesSummary = refM.getReferencesToSummary(entry.getOlatResource(), locale);
if (referencesSummary != null) {
Translator translator = Util.createPackageTranslator(RepositoryManager.class, locale);
errors.setError(translator.translate("details.delete.error.references", new String[] { referencesSummary, entry.getDisplayname() }));
return false;
}
/*
* make an archive of the course nodes with valuable data
*/
UserManager um = UserManager.getInstance();
String charset = um.getUserCharset(identity);
try {
CourseFactory.archiveCourse(entry.getOlatResource(), charset, locale, identity, roles);
} catch (CorruptedCourseException e) {
log.error("The course is corrupted, cannot archive it: " + entry, e);
}
return true;
}
use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.
the class EfficiencyStatementManagerTest method testBigDatas.
@Test
public void testBigDatas() {
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
params.setRoles(new Roles(true, false, false, false, false, false, false));
params.setResourceTypes(Collections.singletonList("CourseModule"));
List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
List<Identity> loadIdentities = securityManager.getVisibleIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, 0, 10000);
int count = 0;
for (RepositoryEntry entry : entries) {
Long resourceableId = entry.getOlatResource().getResourceableId();
try {
ICourse course = CourseFactory.loadCourse(resourceableId);
boolean enabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
if (!enabled) {
course = CourseFactory.openCourseEditSession(entry.getOlatResource().getResourceableId());
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
courseConfig.setEfficencyStatementIsEnabled(true);
CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
}
DBFactory.getInstance().commitAndCloseSession();
try {
int fromIndex = (int) (Math.random() * loadIdentities.size() - 1);
if (fromIndex < 100) {
fromIndex = 100;
}
List<Identity> assessedIdentities = loadIdentities.subList(fromIndex - 100, fromIndex);
// force the storing of the efficiencyStatement - this is usually done only at Learnresource/modify properties/Efficiency statement (ON)
RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
efficiencyStatementManager.updateEfficiencyStatements(courseEntry, assessedIdentities);
} catch (Exception e) {
e.printStackTrace();
}
DBFactory.getInstance().commitAndCloseSession();
DBFactory.getInstance().closeSession();
} catch (CorruptedCourseException e) {
System.out.println("Error");
}
if (count++ % 100 == 0) {
dbInstance.commitAndCloseSession();
}
}
}
use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.
the class AuthorListController method doOverrideCloseResource.
private void doOverrideCloseResource(UserRequest ureq, AuthoringEntryRow row) {
try {
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(row.getResourceType());
if (handler != null) {
String businessPath = "[RepositoryEntry:" + row.getKey() + "]";
ureq.getUserSession().putEntry("override_readonly_" + row.getKey(), Boolean.TRUE);
if (!NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl())) {
tableEl.reloadData();
}
}
} catch (CorruptedCourseException e) {
logError("Course corrupted: " + row.getKey() + " (" + row.getOLATResourceable().getResourceableId() + ")", e);
showError("cif.error.corrupted");
}
}
use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_12_0_0 method processCourseAssessmentLastModified.
private boolean processCourseAssessmentLastModified(RepositoryEntry entry) {
try {
ICourse course = CourseFactory.loadCourse(entry);
CourseNode rootNode = course.getRunStructure().getRootNode();
Set<Identity> changeSet = new HashSet<>();
processCourseNodeAssessmentLastModified(course, entry, rootNode, changeSet);
dbInstance.commitAndCloseSession();
// update structure nodes and efficiency statement if any
Set<Identity> identitiesWithEfficiencyStatements = findIdentitiesWithEfficiencyStatements(entry);
for (Identity assessedIdentity : changeSet) {
UserCourseEnvironment userCourseEnv = AssessmentHelper.createInitAndUpdateUserCourseEnvironment(assessedIdentity, course);
if (identitiesWithEfficiencyStatements.contains(assessedIdentity)) {
efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
}
dbInstance.commitAndCloseSession();
}
} catch (CorruptedCourseException e) {
log.error("Corrupted course: " + entry.getKey(), e);
} catch (Exception e) {
log.error("Unexpected error", e);
} finally {
dbInstance.commitAndCloseSession();
}
return true;
}
Aggregations