use of org.olat.repository.ErrorList in project OpenOLAT by OpenOLAT.
the class RepositoryServiceImpl method deletePermanently.
@Override
public ErrorList deletePermanently(RepositoryEntry entry, Identity identity, Roles roles, Locale locale) {
ErrorList errors = new ErrorList();
boolean debug = log.isDebug();
// invoke handler delete callback
if (debug)
log.debug("deleteRepositoryEntry start entry=" + entry);
entry = (RepositoryEntry) dbInstance.loadObject(entry, true);
if (debug)
log.debug("deleteRepositoryEntry after load entry=" + entry);
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(entry);
OLATResource resource = entry.getOlatResource();
// delete old context
if (!handler.readyToDelete(entry, identity, roles, locale, errors)) {
return errors;
}
userCourseInformationsManager.deleteUserCourseInformations(entry);
certificatesManager.deleteRepositoryEntry(entry);
// delete all bookmarks referencing deleted entry
CoreSpringFactory.getImpl(MarkManager.class).deleteMarks(entry);
// delete all catalog entries referencing deleted entry
catalogManager.resourceableDeleted(entry);
// delete assessment modes
assessmentModeDao.delete(entry);
// delete reminders
reminderDao.delete(entry);
// delete all policies
securityManager.deletePolicies(resource);
// delete reservations
reservationDao.deleteReservations(resource);
// delete references
referenceManager.deleteAllReferencesOf(resource);
// delete all pending tasks
persistentTaskDao.delete(resource);
dbInstance.commit();
// delete lectures
CoreSpringFactory.getImpl(LectureService.class).delete(entry);
dbInstance.commit();
// delete license
CoreSpringFactory.getImpl(LicenseService.class).delete(resource);
dbInstance.commit();
// detach portfolio if there are some lost
CoreSpringFactory.getImpl(PortfolioService.class).detachCourseFromBinders(entry);
dbInstance.commit();
// inform handler to do any cleanup work... handler must delete the
// referenced resourceable a swell.
handler.cleanupOnDelete(entry, resource);
dbInstance.commit();
// delete all test sessions
assessmentTestSessionDao.deleteAllUserTestSessionsByCourse(entry);
// nullify the reference
assessmentEntryDao.removeEntryForReferenceEntry(entry);
assessmentEntryDao.deleteEntryForRepositoryEntry(entry);
dbInstance.commit();
if (debug)
log.debug("deleteRepositoryEntry after reload entry=" + entry);
deleteRepositoryEntryAndBaseGroups(entry);
if (debug)
log.debug("deleteRepositoryEntry Done");
return errors;
}
use of org.olat.repository.ErrorList in project openolat by klemens.
the class ConfirmDeletePermanentlyController method deleteEntries.
private boolean deleteEntries(UserRequest ureq, List<RepositoryEntry> entries, List<ErrorList> errorList) {
boolean allOk = true;
Roles roles = ureq.getUserSession().getRoles();
for (RepositoryEntry entry : entries) {
RepositoryEntry reloadedEntry = repositoryService.loadByKey(entry.getKey());
if (reloadedEntry != null) {
ErrorList errors = repositoryService.deletePermanently(reloadedEntry, getIdentity(), roles, getLocale());
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(reloadedEntry, OlatResourceableType.genRepoEntry));
if (errors.hasErrors()) {
allOk = false;
errorList.add(errors);
} else {
EntryChangedEvent e = new EntryChangedEvent(reloadedEntry, getIdentity(), Change.deleted, "delete");
ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(e, RepositoryService.REPOSITORY_EVENT_ORES);
}
}
}
return allOk;
}
use of org.olat.repository.ErrorList in project OpenOLAT by OpenOLAT.
the class CourseWebService method deleteCourse.
/**
* Delete a course by id.
*
* @response.representation.200.doc The metadatas of the deleted course
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param request The HTTP request
* @return It returns the XML representation of the <code>Structure</code>
* object representing the course.
*/
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!isAuthorEditor(course, request) && !isInstitutionalResourceManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
if (errors.hasErrors()) {
return Response.serverError().status(500).build();
}
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
return Response.ok().build();
}
use of org.olat.repository.ErrorList in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method deleteCourse.
/**
* Delete a resource by id
*
* @response.representation.200.doc The metadatas of the deleted resource
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param courseId The course resourceable's id
* @param request The HTTP request
* @return It returns the XML representation of the <code>Structure</code>
* object representing the course.
*/
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(re, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
if (errors.hasErrors()) {
return Response.serverError().status(500).build();
}
ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
return Response.ok().build();
}
use of org.olat.repository.ErrorList in project OpenOLAT by OpenOLAT.
the class ConfirmDeletePermanentlyController method doCompleteDelete.
private void doCompleteDelete(UserRequest ureq) {
List<ErrorList> errorList = new ArrayList<>();
boolean allOk = deleteEntries(ureq, rows, errorList);
if (allOk && deleteReferencesEl.isVisible() && deleteReferencesEl.isEnabled() && deleteReferencesEl.isOneSelected() && deleteReferencesEl.isSelected(0)) {
Map<Long, ReferenceInfos> referencesMap = new HashMap<>();
for (ReferenceInfos reference : references) {
referencesMap.put(reference.getEntry().getKey(), reference);
}
Collection<String> selectedKeys = referencesEl.getSelectedKeys();
List<RepositoryEntry> referencesToDelete = new ArrayList<>(selectedKeys.size());
for (String selectedRefKey : selectedKeys) {
Long key = new Long(selectedRefKey);
ReferenceInfos refInfos = referencesMap.get(key);
if (refInfos != null && refInfos.isOrphan() && refInfos.isOwner() && !refInfos.isManaged()) {
referencesToDelete.add(referencesMap.get(key).getEntry());
}
}
allOk &= deleteEntries(ureq, referencesToDelete, errorList);
}
if (allOk) {
showInfo("info.entry.deleted");
} else {
List<String> msgs = new ArrayList<>();
for (ErrorList error : errorList) {
if (StringHelper.containsNonWhitespace(error.getFirstError())) {
msgs.add(error.getFirstError());
}
}
if (msgs.size() == 1) {
getWindowControl().setWarning(msgs.get(0));
} else if (msgs.size() > 1) {
StringBuilder sb = new StringBuilder();
sb.append("<ul>");
for (String msg : msgs) {
sb.append("<li>").append(msg).append("</li>");
}
sb.append("</ul>");
getWindowControl().setWarning(sb.toString());
} else {
showWarning("info.could.not.delete.entry");
}
}
}
Aggregations